diff --git a/public_html/classes/campaign.php b/public_html/classes/campaign.php index 6165b5d..f88f030 100644 --- a/public_html/classes/campaign.php +++ b/public_html/classes/campaign.php @@ -36,7 +36,8 @@ class Campaign extends CPHPDatabaseRecordClass 'HaveData' => "HaveData" ), 'timestamp' => array( - 'LastStatisticsUpdate' => "LastStatisticsUpdate" + 'LastStatisticsUpdate' => "LastStatisticsUpdate", + 'CreationDate' => "CreationDate" ), 'user' => array( 'Owner' => "OwnerId" @@ -61,6 +62,29 @@ class Campaign extends CPHPDatabaseRecordClass return self::CreateFromQuery("SELECT * FROM campaigns WHERE `UrlName` = :UrlName", array(':UrlName' => $urlname), 0, true); } + public static function GenerateUrlName($name) + { + $found = false; + $iteration = 0; + $sUrlName = ""; + + try + { + while(true) + { + $sUrlName = generate_urlname($name, $iteration); + $result = Campaign::FindByUrlName($sUrlName); + $iteration += 1; + } + } + catch (NotFoundException $e) + { + /* Current UrlName is not in use */ + } + + return $sUrlName; + } + public function VerifyAdministratorAccess($userid) { return ($this->sOwnerId == $userid); diff --git a/public_html/includes/base.php b/public_html/includes/base.php index 9354163..78c3a69 100644 --- a/public_html/includes/base.php +++ b/public_html/includes/base.php @@ -127,3 +127,17 @@ function send_mail($to, $subject, $text, $html) //$mail_transport->send($sMessage); } + +function generate_urlname($input, $iteration) +{ + $uUrlName = preg_replace("/[ =_+]/", "-", $input); + $sUrlName = preg_replace("/[^a-zA-Z0-9-]/", "", $uUrlName); + $sUrlName = strtolower($sUrlName); + + if($iteration > 0) + { + $sUrlName .= "-" . $iteration; + } + + return $sUrlName; +} diff --git a/public_html/modules/campaign/create.php b/public_html/modules/campaign/create.php new file mode 100644 index 0000000..b57bd29 --- /dev/null +++ b/public_html/modules/campaign/create.php @@ -0,0 +1,39 @@ +uName = $_POST['name']; + $sCampaign->uOwnerId = $sCurrentUser->sId; + $sCampaign->uCreationDate = time(); + $sCampaign->uAllowOneTime = isset($_POST['allow_once']); + $sCampaign->uUrlName = Campaign::GenerateUrlName($_POST['name']); + $sCampaign->InsertIntoDatabase(); + + flash_notice("Your campaign was successfully created. You should add a payment method now."); + redirect("/dashboard/{$sCampaign->uUrlName}"); + } +} + +$sPageTitle = "Create new campaign"; +$sPageContents = NewTemplater::Render("campaign/create", $locale->strings, array()); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index f1a936e..80a179d 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -33,6 +33,11 @@ $router->routes = array( "^/about$" => "modules/about.php", "^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php", "^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php", + "^/create$" => array( + 'target' => "modules/campaign/create.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), "^/dashboard$" => array( 'target' => "modules/dashboard.php", 'authenticator' => "authenticators/user.php", diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index 9b7f984..abe23b6 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -201,7 +201,7 @@ pre.debug float: left; } -.formfield input, .formfield select +.formfield input:not([type=checkbox]), .formfield select { font-size: 17px; padding: 4px; @@ -212,6 +212,13 @@ pre.debug background-color: #F4FDE4; } +.formfield input[type=checkbox] +{ + margin-top: 10px; + width: 18px; + height: 18px; +} + .formfield label { width: 170px; @@ -226,6 +233,16 @@ form.narrow .formfield label width: 130px; } +form.wide .formfield label +{ + width: 230px; +} + +form.wide .formfield input:not([type=checkbox]) +{ + width: 210px; +} + .formfield.submit { padding-left: 182px; @@ -237,6 +254,11 @@ form.narrow .formfield.submit padding-left: 142px; } +form.wide .formfield.submit +{ + padding-left: 200px; +} + form .note { clear: both; @@ -741,7 +763,20 @@ p.pledge-button margin-right: 12px; } -.complex-header .button +/************************************** + * TOOLBAR * + **************************************/ + +.toolbar +{ + margin: 16px 4px; +} + +/************************************** + * CONTEXT BUTTONS * + **************************************/ + +a.button { float: left; display: block; @@ -756,7 +791,7 @@ p.pledge-button color: black; } -.complex-header .button:hover +a.button:hover { border: 1px solid #587532; background-color: #F1FFD0; diff --git a/public_html/templates/campaign/create.tpl b/public_html/templates/campaign/create.tpl new file mode 100644 index 0000000..98be032 --- /dev/null +++ b/public_html/templates/campaign/create.tpl @@ -0,0 +1,32 @@ +

Create new campaign

+ +{%if isempty|errors == false} +
+ One or more errors occurred: + +
+{%/if} + +
+
+
+ + {%input type="text" name="name"} +
+
+ +
+ + {%input type="checkbox" name="allow_once"} +
+
+ +
+ +
+
+
diff --git a/public_html/templates/dashboard.tpl b/public_html/templates/dashboard.tpl index cedea74..05b3a8a 100644 --- a/public_html/templates/dashboard.tpl +++ b/public_html/templates/dashboard.tpl @@ -64,3 +64,8 @@ + +
+ Create new campaign +
+