Implement campaign creation

master
Sven Slootweg 12 years ago
parent ea90903198
commit e816b020e1

@ -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);

@ -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;
}

@ -0,0 +1,39 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
if(!empty($_POST['submit']))
{
if(empty($_POST['name']))
{
flash_error("You did not enter a valid campaign name.");
}
if(count(get_errors(false)) == 0)
{
$sCampaign = new Campaign(0);
$sCampaign->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());

@ -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",

@ -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;

@ -0,0 +1,32 @@
<h2 class="spaced">Create new campaign</h2>
{%if isempty|errors == false}
<div class="errors">
One or more errors occurred:
<ul>
{%foreach error in errors}
<li>{%?error}</li>
{%/foreach}
</ul>
</div>
{%/if}
<div class="formwrapper">
<form method="post" action="/create" class="wide">
<div class="formfield">
<label>Campaign name</label>
{%input type="text" name="name"}
<div class="clear"></div>
</div>
<div class="formfield">
<label>Allow one-off donations</label>
{%input type="checkbox" name="allow_once"}
<div class="clear"></div>
</div>
<div class="formfield submit">
<button type="submit" name="submit" value="submit">Create</button>
</div>
</form>
</div>

@ -64,3 +64,8 @@
<td></td>
</tr>
</table>
<div class="toolbar">
<a class="button" href="/create">Create new campaign</a>
<div class="clear"></div>
</div>

Loading…
Cancel
Save