Added extension: vanilla-voting-0.2beta-0.2beta.zip
[vanilla-miry.git] / extensions / VanillaVoting / library / PostBackControl.VanillaVotingForm.php
blob86ab0c75e150e45bf6afdc5238419963098a94df
1 <?php
2 /**
3 * VanillaVoting class. This is where all the Admin side forms are generated
4 */
5 class VanillaVotingForm extends PostBackControl
7 var $ConfigurationManager;
8 var $AllowedCategory;
9 var $CategoryCheckboxes;
11 function VanillaVotingForm(&$Context)
13 $this->Name = 'VanillaVotingForm';
14 $this->ValidActions = array('VanillaVoting','ProcessVanillaVoting');
15 $this->Constructor($Context);
17 if($this->IsPostBack)
19 $SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php';
20 $this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
21 if ($this->PostBackAction == 'ProcessVanillaVoting')
23 $this->ConfigurationManager->GetSettingsFromForm($SettingsFile);
24 $this->ConfigurationManager->DefineSetting('VANILLAVOTING_CATEGORYID', implode(",", $_POST['AllowedCategory']), 0);
25 $this->DelegateParameters['ConfigurationManager'] = &$this->ConfigurationManager;
26 // And save everything
27 if ($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
28 header('location: '.GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=VanillaVoting&Success=1'));
29 } else {
30 $this->PostBackAction = 'VanillaVoting';
36 function Render()
38 if ($this->IsPostBack)
40 $this->PostBackParams->Clear();
41 if ($this->PostBackAction == 'VanillaVoting')
43 $this->AllowedCategory = explode(",", $this->Context->Configuration["VANILLAVOTING_CATEGORYID"]);
44 // Load the category selector
45 $cm = $this->Context->ObjectFactory->NewContextObject($this->Context, 'CategoryManager');
46 $CategoryData = $cm->GetCategories(0, 1);
47 $cat = $this->Context->ObjectFactory->NewObject($this->Context, 'Category');
48 while ($Row = $this->Context->Database->GetRow($CategoryData)) {
49 $cat->Clear();
50 $cat->GetPropertiesFromDataSet($Row);
51 $this->CategoryCheckboxes .= "<li><p><span>".GetDynamicCheckBox("AllowedCategory[]", $cat->CategoryID,
52 (in_array($cat->CategoryID, $this->AllowedCategory)) ? 1 : 0,
53 "",$cat->Name,"","Category_".$cat->CategoryID )."</span></p></li>\r\n";
56 $this->PostBackParams->Set('PostBackAction', 'ProcessVanillaVoting');
58 echo '<div id="Form" class="Account VanillaVotingSettings Preferences">';
59 if (ForceIncomingInt('Success', 0)) echo '<div id="Success">'.$this->Context->GetDefinition('ChangesSaved').'</div>';
60 echo '<fieldset>
61 <legend>'.$this->Context->GetDefinition("VanillaVoting").'</legend>
62 '.$this->Get_Warnings().'
63 '.$this->Get_PostBackForm('frmVanillaVoting').'
64 <ul>
65 <li>
66 <p class="Description"><strong>'.$this->Context->GetDefinition("VanillaVotingCategory").'</strong></p>
67 <p class="Description">Check: <a onclick="CheckAll(\'Category_\'); return false;" href="./">All</a>, <a onclick="CheckNone(\'Category_\'); return false;" href="./">None</a></p>
68 </li>
69 '.$this->CategoryCheckboxes.'
70 </ul>
71 <div class="Submit">
72 <input type="submit" name="btnSave" value="'.$this->Context->GetDefinition('Save').'" class="Button SubmitButton" />
73 <a href="'.GetUrl($this->Context->Configuration, $this->Context->SelfUrl).'" class="CancelButton">'.$this->Context->GetDefinition('Cancel').'</a>
74 </div>
75 </form>
76 </fieldset>
77 </div>';