function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     // Add a first set of elements
     $form->addElement('date', 'date1', 'Date1', '');
     $form->addElement('date', 'date2', 'Date2 (monthabbr = true)', array('id' => 'mydate'), array('monthabbr' => true));
     $form->addElement('date', 'date3', 'Date3 (monthnumber = true)', '', array('monthnumber' => true));
     $form->addElement('date', 'date4', 'Date4 (monthucfirst = true)', '', array('monthucfirst' => true));
     $form->addElement('date', 'date5', 'Date5 (yearstart = 1970, yearend=2007, yeartwodigits = true)', '', array('yearstart' => 1970, 'yearend' => 2007, 'yeartwodigits' => true));
     $form->addElement('date', 'time1', 'Time1', '', array('time'));
     $form->addElement('date', 'time2', 'Time2 (minutesoffset = 10)', '', array('time', 'minutesoffset' => 10));
     $form->addElement('date', 'time3', 'Time3 (secondsoffset = 15)', '', array('time', 'secondsoffset' => 15));
     $form->addElement('date', 'datetime1', 'DateTime1', '', array('datetime'));
     $form->addElement('date', 'date6', 'Date6 (month, year)', '', array('month', 'year'));
     $form->addElement('date', 'date7', 'Date7 (day, month)', '', array('day', 'month'));
     $form->addElement('date', 'date8', 'Date8 (day, hours, minutes)', '', array('day', 'hours', 'minutes'));
     $form->addElement('submit', '_cmdSubmit', 'Submit');
     // Add rules
     $form->addRule(array('date1', 'date2', 'date3', 'date4', 'date5', 'time1', 'time2', 'time3', 'datetime1', 'date6', 'date7', 'date8'), 'date', 'must be a valid date');
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), '$form->getValues()');
     }
     // Display form
     $form->display();
 }
Exemplo n.º 2
0
 function actionDefault()
 {
     // Create the delete form
     $form = new YDForm('clearCacheForm');
     $form->addElement('checkbox', 'cache_tmb', 'Thumbnail cache');
     $form->addElement('checkbox', 'cache_web', 'Web download cache');
     $form->addElement('checkbox', 'cache_tpl', 'Template cache');
     $form->addElement('submit', '_cmdSubmit', t('cleanup'), array('class' => 'button'));
     $form->setDefaults(array('cache_web' => 1, 'cache_tmb' => 1, 'cache_tpl' => 1));
     // Validate the form
     if ($form->validate() == true) {
         // Check if we need to delete the thumbnail objects
         if ($form->getValue('cache_tmb') === 'on') {
             $this->_deleteCacheFiles('*.tmn');
         }
         // Check if we need to delete the web objects
         if ($form->getValue('cache_web') === 'on') {
             $this->_deleteCacheFiles('*.wch');
         }
         // Check if we need to delete the template objects
         if ($form->getValue('cache_tpl') === 'on') {
             $this->_deleteCacheFiles('*.tpl.php');
         }
         // Add a status message
         $this->tpl->assign('message', t('cache_cleaned_up'));
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $elementDate = $form->addElement('dateselect', 'dateSelect1', 'Enter data:');
     $elementDate = $form->addElement('dateselect', 'dateSelect2', 'Enter data:');
     $elementTime = $form->addElement('timeselect', 'timeSelect1', 'Enter data:');
     $elementDateTime = $form->addElement('datetimeselect', 'datetimeSelect1', 'Enter data:');
     $form->addElement('submit', 'cmd1', 'Send');
     $form->setDefaults(array('dateSelect1' => array('month' => 4, 'day' => 4, 'year' => 2002)));
     if (YD_DEBUG == 1) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('txt1'), 'txt1');
         YDDebugUtil::dump($form->getValue('txt2'), 'txt2');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
     }
     if ($form->validate()) {
         YDDebugUtil::dump($elementDate->getTimeStamp(), '$elementDate->getTimeStamp()');
         YDDebugUtil::dump($elementDate->getTimeStamp('%d/%m/%Y'), '$elementDate->getTimeStamp( "%d/%m/%Y" )');
         YDDebugUtil::dump(date('M-d-Y', $elementDate->getTimeStamp()), '$elementDate->gdate( getTimeStamp() )');
         YDDebugUtil::dump($elementTime->getTimeStamp(), '$elementTime->getTimeStamp()');
         YDDebugUtil::dump($elementTime->getTimeStamp('%H:%M'), '$elementTime->getTimeStamp( "%H:%M" )');
         YDDebugUtil::dump($elementDateTime->getTimeStamp(), '$elementDateTime->getTimeStamp()');
         YDDebugUtil::dump($elementDateTime->getTimeStamp('%d/%m/%Y %H:%M'), '$elementDateTime->getTimeStamp( "%H:%M" )');
     }
     $form->display();
 }
Exemplo n.º 4
0
 function actionSearch()
 {
     // retrieve list of forums
     $forumLogic = new ForumsLogic();
     $forums = $forumLogic->retrieveAllByOrderSimple();
     $selectForums = array();
     foreach ($forums as $i => $item) {
         $selectForums["" . $item->id] = $item->name;
     }
     // Create the search form
     $form = new YDForm('searchForm');
     $form->addElement('text', 'searchKeys', t('forums.searchstring'), array("size" => 40));
     $form->addElement('select', 'searchForum', t('forums.searchforum'), array("width" => 60), $selectForums);
     $form->addElement('submit', 'cmdSubmit', t('forums.search'));
     // Add rules
     $form->addFormRule(array(&$this, 'checkSearch'));
     // Process the form
     if ($form->validate()) {
         $this->actionTpl->assign('searched', true);
         // get and show results
         $forum = $forumLogic->retrieveForumById($form->getValue('searchForum'));
         $forum->loadSubjectsMatching($form->getValue('searchKeys'));
         // number of results
         $this->actionTpl->assign('nbposts', count($forum->subjects));
         $this->actionTpl->assign('posts', $forum->subjects);
     }
     // Assign variables to the template
     $this->actionTpl->assign('form', $form->toArray());
     $content = new page($this->actionTpl->fetch('templates/forums.search.tpl'), t('forums.searching'));
     $this->display($content);
 }
 function actionDefault()
 {
     // Mark the form as not valid
     $this->setVar('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             $file->moveUpload('.');
         }
         // Mark the form as valid
         $this->setVar('formValid', true);
     }
     // Add the form to the template
     $this->setVar('form_html', $form->toHtml());
     $this->addForm('form', $form);
     // Output the template
     $this->outputTemplate();
 }
Exemplo n.º 6
0
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $form->registerFilter('reverse', 'strrev');
     $form->setDefaults(array('txt2' => 'First text', 'txt3' => "2\nlines", 'hid1' => 'me hidden', 'chk1' => 'x', 'chk2' => false, 'sel1' => 2));
     $text =& $form->addElement('text', 'txt1', 'Enter text 1:');
     $text->_label = 'new label for txt1';
     $form->addElement('text', 'txt2', 'Enter text 2:', array('class' => 'textInputClass', 'name' => 'x'));
     $form->addElement('textarea', 'txt3', 'Enter text 2:');
     $form->addElement('textareacounter', 'txtcounter_1', 'Textarea counter 1', array(), array('maxlength' => 10, 'before' => ' (', 'after' => ' characters remaining)'));
     $form->addElement('textareacounter', 'txtcounter_2', 'Textarea counter 2');
     $form->addElement('radio', 'rad1', 'Select a value 1:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('radio', 'rad2', 'Select a value 2:', array(), array(1 => 'een<br/>', 2 => 'twee'));
     $form->addElement('hidden', 'hid1', '');
     $form->addElement('hidden', 'hid2', '', array(), 'i am also hidden');
     $form->addElement('image', 'img1', '', array(), 'http://www.scripting.com/images/xml.gif');
     $form->addElement('password', 'pas1', 'Enter your password');
     $form->addElement('bbtextarea', 'bbt1', 'Enter your BBCode');
     $form->addElement('checkbox', 'chk1', 'Select me please');
     $form->addElement('checkbox', 'chk2', 'Select me please');
     $form->addElement('select', 'sel1', 'Select an option:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('span', 'span1', 'This is a span. The next element is an image (img).');
     $form->addElement('img', 'img2', 'http://www.scripting.com/images/xml.gif');
     $form->addElement('file', 'fil1', 'Select an file:');
     $form->addElement('submit', 'cmd1', 'Send');
     $form->addElement('reset', 'res1', 'Reset');
     $form->addFilter('__ALL__', 'upper');
     $form->addFilter('txt1', 'trim');
     $form->addFilter('txt2', 'reverse');
     $form->addRule('txt1', 'required', 'txt1 is required');
     $form->addRule('chk2', 'exact', 'chk2 is required', 1);
     $form->addFormRule(array(&$this, 'formrule'), 'txt1 is required');
     if (YDConfig::get('YD_DEBUG') == 1 || YDConfig::get('YD_DEBUG') == 2) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('txt1'), 'txt1');
         YDDebugUtil::dump($form->getValue('txt2'), 'txt2');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
         YDDebugUtil::dump($form->toArray());
     }
     if ($form->validate()) {
         YDDebugUtil::dump($form->getModifiedValues(), 'Form modified values');
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
     // Create the form
     $form2 = new YDForm('form2');
     $form2->setDefaults(array('txt1' => 'First text'));
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('submit', 'cmd1', 'Send');
     $form2->display();
 }
 function actionDefault()
 {
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     //$form->addRule( 'file1', 'maxlength', 'Path can only be 8 characters', 8 );
     $form->addRule('file1', 'maxfilesize', 'Maximum filesize of 10 KB is exceeded!', 10 * 1024);
     //$form->addRule( 'file1', 'extension', 'File extension should be txt!', 'txt' );
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             // Move the upload
             $file->moveUpload('.');
             // Mark the form as valid
             $this->template->assign('formValid', true);
         }
     }
     // Add the form to the template
     $this->template->assign('form_html', $form->toHtml());
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $form->addElement('text', 'text1', 'Enter text 1:');
     $form->addElement('text', 'text2', 'Enter text 2:');
     $form->addElement('textarea', 'textarea', 'Enter text 3:');
     $form->addElement('radio', 'radio1', 'Select a value 1:', array(), array(1 => 'one', 2 => 'two'));
     $form->addElement('radio', 'radio2', 'Select a value 2:', array(), array(1 => 'one', 2 => 'two'));
     $form->addElement('hidden', 'hidden1', '');
     $form->addElement('hidden', 'hidden2', '', array(), 'i am also hidden');
     $form->addElement('image', 'image', '', array(), 'http://www.scripting.com/images/xml.gif');
     $form->addElement('password', 'password', 'Enter your password');
     $form->addElement('bbtextarea', 'bbtextarea', 'Enter your BBCode');
     $form->addElement('checkbox', 'checkbox1', 'Check me 1');
     $form->addElement('checkbox', 'checkbox2', 'Check me 2');
     $form->addElement('select', 'select', 'Select an option:', array(), array(1 => 'one', 2 => 'two'));
     $form->addElement('dateselect', 'dateselect', 'Select a date:');
     $form->addElement('datetimeselect', 'datetimeselect', 'Select a date:');
     $form->addElement('timeselect', 'timeselect', 'Select a date:');
     $form->addElement('file', 'file', 'Select an file:');
     $form->addElement('submit', 'submit', 'Send');
     $form->addElement('button', 'button', 'Button');
     $form->addElement('reset', 'resest', 'Reset');
     $form->setDefaults(array('radio1' => 1, 'radio2' => 2, 'text1' => 'my text one', 'select' => 1, 'checkbox1' => 'on'));
     if ($form->validate()) {
         YDDebugUtil::dump($form->getDefaults(), 'Form default values');
         YDDebugUtil::dump($form->getModifiedValues(), 'Form modified values');
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
 }
 function actionLogin()
 {
     // Redirect to default action if already logged in
     if ($this->isAuthenticated() === true) {
         $this->forward('default');
         return;
     }
     // Create the login form
     $form = new YDForm('loginForm');
     $form->setDefaults(array('name' => 'Joe User'));
     $form->addElement('text', 'loginName', 'User name:');
     $form->addElement('password', 'loginPass', 'Password:'******'submit', 'cmdSubmit', 'Login');
     // Add the rules
     $form->addFormRule(array(&$this, 'checkLogin'));
     // Process the form
     if ($form->validate()) {
         // Get username and password
         $usrName = $form->getValue('loginName');
         $usrPass = $form->getValue('loginPass');
         // Mark the session that we are logged in
         $_SESSION['usrName'] = 'pieter';
         $_SESSION['isLoggedIn'] = true;
         // Mark the form as valid
         $this->authenticationSucceeded();
         $this->forward('default');
         return;
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display('login');
 }
Exemplo n.º 10
0
 function actionAddNote()
 {
     // Create the add form
     $form = new YDForm('addEntryForm');
     // Add the elements
     $form->addElement('text', 'title', 'Title:');
     $form->addElement('textarea', 'body', 'Contents:');
     $form->addElement('submit', 'cmdSubmit', 'Save');
     // Apply filters
     $form->addFilter('title', 'trim');
     $form->addFilter('body', 'trim');
     // Add a rule
     $form->addRule('title', 'required', 'Title is required');
     $form->addRule('body', 'required', 'Contents is required');
     // Process the form
     if ($form->validate()) {
         // Save the entries in an array
         $entry = array('id' => md5($form->getValue('title') . $form->getValue('body')), 'title' => $form->getValue('title'), 'body' => $form->getValue('body'));
         // Save the serialized entry to a file
         $this->dataDir->createFile($entry['id'] . '.dat', YDObjectUtil::serialize($entry));
         // Forward to the list view
         $this->forward('default');
         // Return
         return;
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
 function actionDefault()
 {
     // Create the form
     echo '<p><b>Compare rule: equal</b></p>';
     $form1 = new YDForm('form_equal');
     $form1->addElement('text', 'txt1', 'Enter text 1:');
     $form1->addElement('text', 'txt2', 'Enter text 2:');
     $form1->addElement('text', 'txt3', 'Enter text 3:');
     $form1->addElement('submit', 'cmd1', 'equal');
     // Add the rules
     $form1->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form1->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form1->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form1->addCompareRule(array('txt1', 'txt2', 'txt3'), 'equal', 'txt1, txt2 and txt3 should be equal');
     // Validate or show the form
     if ($form1->validate()) {
         YDDebugUtil::dump($form1->getValues(), 'Form1 values');
     } else {
         $form1->display();
     }
     // Create the form
     echo '<p><b>Compare rule: asc</b></p>';
     $form2 = new YDForm('form_asc');
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('text', 'txt3', 'Enter text 3:');
     $form2->addElement('submit', 'cmd1', 'asc');
     // Add the rules
     $form2->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form2->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form2->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form2->addCompareRule(array('txt1', 'txt2', 'txt3'), 'asc', 'txt1 < txt2 < txt3');
     // Validate or show the form
     if ($form2->validate()) {
         YDDebugUtil::dump($form2->getValues(), 'Form2 values');
     } else {
         $form2->display();
     }
     // Create the form
     echo '<p><b>Compare rule: desc</b></p>';
     $form3 = new YDForm('form_desc');
     $form3->addElement('text', 'txt1', 'Enter text 1:');
     $form3->addElement('text', 'txt2', 'Enter text 2:');
     $form3->addElement('text', 'txt3', 'Enter text 3:');
     $form3->addElement('submit', 'cmd1', 'desc');
     // Add the rules
     $form3->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form3->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form3->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form3->addCompareRule(array('txt1', 'txt2', 'txt3'), 'desc', 'txt1 > txt2 > txt3');
     // Validate or show the form
     if ($form3->validate()) {
         YDDebugUtil::dump($form3->getValues(), 'Form3 values');
     } else {
         $form3->display();
     }
 }
Exemplo n.º 12
0
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $form->registerFilter('reverse', 'strrev');
     $form->setDefaults(array('txt2' => 'First text', 'txt3' => "2\nlines", 'hid1' => 'me hidden', 'chk1' => 'x', 'sel1' => 2));
     $text =& $form->addElement('text', 'txt1', 'Enter text 1:');
     $text->_label = 'new label for txt1';
     $form->addElement('text', 'txt2', 'Enter text 2:', array('class' => 'textInputClass', 'name' => 'x'));
     $form->addElement('textarea', 'txt3', 'Enter text 2:');
     $form->addElement('radio', 'rad1', 'Select a value 1:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('radio', 'rad2', 'Select a value 2:', array(), array(1 => 'een<br/>', 2 => 'twee'));
     $form->addElement('hidden', 'hid1', '');
     $form->addElement('hidden', 'hid2', '', array(), 'i am also hidden');
     $form->addElement('image', 'img1', '', array(), 'http://www.yellowduck.be/images/site_images/rss091.gif');
     $form->addElement('password', 'pas1', 'Enter your password');
     $form->addElement('bbtextarea', 'bbt1', 'Enter your BBCode');
     $form->addElement('checkbox', 'chk1', 'Select me please');
     $form->addElement('checkbox', 'chk2', 'Select me please');
     $form->addElement('select', 'sel1', 'Select an option:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('file', 'fil1', 'Select an file:');
     $form->addElement('submit', 'cmd1', 'Send');
     $form->addElement('reset', 'res1', 'Reset');
     $form->addFilter('__ALL__', 'upper');
     $form->addFilter('txt1', 'trim');
     $form->addFilter('txt2', 'reverse');
     $form->addRule('txt1', 'required', 'txt1 is required');
     $form->addRule('chk2', 'required', 'chk2 is required');
     $form->addFormRule(array(&$this, 'formrule'), 'txt1 is required');
     if (YD_DEBUG == 1) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('txt1'), 'txt1');
         YDDebugUtil::dump($form->getValue('txt2'), 'txt2');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
     }
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
     // Create the form
     $form2 = new YDForm('form2');
     $form2->setDefaults(array('txt1' => 'First text'));
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('submit', 'cmd1', 'Send');
     $form2->display();
 }
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     // Add the checkboxgroup
     $form->addElement('checkboxgroup', 'choose_multiple', 'Choose multiple default', array(), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple2', 'Choose multiple HORIZONTAL', array('sep' => 'h'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple3', 'Choose multiple VERTICAL', array('sep' => 'v'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple4', 'Choose multiple LEFT', array('sep' => 'l'), array(0 => 'choice 1', 1 => 'choice 2'));
     $el =& $form->addElement('checkboxgroup', 'choose_multiple5', 'Choose multiple RIGHT', array('sep' => 'r'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple6', 'Choose multiple VERTICAL LEFT', array('sep' => 'vl'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple7', 'Choose multiple VERTICAL RIGHT', array('sep' => 'vr'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple8', 'Choose multiple HORIZONTAL LEFT', array('sep' => 'hl'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple9', 'Choose multiple HORIZONTAL RIGHT', array('sep' => 'hr'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple10', 'Custom Separator "|"', array('separator' => '&nbsp;|&nbsp;'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple11', 'Custom Separator "XXX" and LEFT', array('sep' => 'l', 'separator' => '&nbsp;&nbsp;XXX&nbsp;&nbsp;'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple12', 'Custom Separator "...", LEFT and VERTICAL', array('sep' => 'l', 'separator' => '...<br />'), array(0 => 'choice 1', 1 => 'choice 2'));
     $form->addElement('checkboxgroup', 'choose_multiple_big', 'Choose with column format', array(), array(0 => 'choice 1', 'choice 2', 'choice 3', 'choice 4', 'choice 5', 'choice 6', 'choice 7', 'choice 8'));
     $el2 =& $form->addElement('checkboxgroup', 'choose_multiple_big2', 'Choose with column format (2 columns)', array(), array(0 => 'choice 1', 'choice 2', 'choice 3', 'choice 4', 'choice 5', 'choice 6', 'choice 7', 'choice 8'));
     $el2->setColumns(2);
     $el3 =& $form->addElement('checkboxgroup', 'choose_multiple_big3', 'Choose with column format (3 columns and a default "select all")', array(), array(0 => 'choice 1', 'choice 2', 'choice 3', 'choice 4', 'choice 5', 'choice 6', 'choice 7', 'choice 8', 'choice 9'));
     $el3->setColumns(3);
     $el3->addSelectAll();
     $el4 =& $form->addElement('checkboxgroup', 'choose_multiple_big4', 'Choose with column format (3 columns and a "select all" on top)', array(), array(0 => 'choice 1', 'choice 2', 'choice 3', 'choice 4', 'choice 5', 'choice 6', 'choice 7', 'choice 8'));
     $el4->setColumns(3);
     $el4->addSelectAll(false);
     // demonstrate disable on checkboxgroup
     $form->disable('choose_multiple', 1);
     $form->disable('choose_multiple2', array(0, 1));
     $form->disable('choose_multiple3');
     // Add and example about 'select all' button
     $el->addSelectAll();
     // Add the submit button
     $form->addElement('submit', 'btnSubmit', 'submit');
     // Set the defaults
     $form->setDefaults(array('choose_multiple' => array(0 => 0, 1 => 1)));
     // Process the form
     if ($form->validate() === true) {
         YDDebugUtil::dump($form->getValues());
     }
     // Add the template
     $tpl = new YDTemplate();
     // Add the form to the template
     $tpl->assign('form', $form->toHTML());
     // Display the template
     $tpl->display();
 }
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     // Add a first set of elements
     $elementDate = $form->addElement('dateselect', 'dateSelect1', 'Enter data:');
     $elementTime = $form->addElement('timeselect', 'timeSelect1', 'Enter data:');
     $elementDateTime = $form->addElement('datetimeselect', 'datetimeSelect1', 'Enter data:');
     // Add a second set of elements
     $form->addElement('dateselect', 'dateSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050'));
     $form->addElement('timeselect', 'timeSelect2', 'Enter data:');
     $form->addElement('datetimeselect', 'datetimeSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050'));
     $form->addElement('datetimeselect', 'datetimeSelect3', 'Enter data with seconds:', array(), array('seconds' => true));
     // Add the send button
     $form->addElement('submit', 'cmd1', 'Send');
     // Set the defaults
     $form->setDefaults(array('dateSelect1' => array('month' => 4, 'day' => 4, 'year' => 2002), 'dateSelect2' => strval(time()), 'timeSelect2' => strval(time()), 'datetimeSelect2' => time() + 3600 * 24));
     // Display the form
     $form->display();
     // Show the contents of the form
     if (YDConfig::get('YD_DEBUG') == 1) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('dateSelect1'), 'dateSelect1');
         YDDebugUtil::dump($form->getValue('timeSelect1'), 'timeSelect1');
         YDDebugUtil::dump($form->getValue('datetimeSelect1'), 'datetimeSelect1');
         YDDebugUtil::dump($form->getValues(), '$form->getValues()');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
     }
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), '$form->getValues()');
         YDDebugUtil::dump($elementDate->getTimeStamp(), '$elementDate->getTimeStamp()');
         YDDebugUtil::dump($elementDate->getTimeStamp('%d/%m/%Y'), '$elementDate->getTimeStamp( "%d/%m/%Y" )');
         YDDebugUtil::dump(date('M-d-Y', $elementDate->getTimeStamp()), '$elementDate->gdate( getTimeStamp() )');
         YDDebugUtil::dump($elementTime->getTimeStamp(), '$elementTime->getTimeStamp()');
         YDDebugUtil::dump($elementTime->getTimeStamp('%H:%M'), '$elementTime->getTimeStamp( "%H:%M" )');
         YDDebugUtil::dump($elementDateTime->getTimeStamp(), '$elementDateTime->getTimeStamp()');
         YDDebugUtil::dump($elementDateTime->getTimeStamp('%d/%m/%Y %H:%M'), '$elementDateTime->getTimeStamp( "%H:%M" )');
         YDDebugUtil::dump(YDStringUtil::formatDate($elementDateTime, 'datetime', 'pt'), 'YDStringUtil::formatDate');
     }
 }
Exemplo n.º 15
0
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('myForm');
     $form->setDefaults(array('name' => 'Joe User'));
     $form->addElement('text', 'loginName', 'User name:');
     $form->addElement('password', 'loginPass', 'Password:'******'submit', 'cmdSubmit', 'Login');
     // Add the form rule
     $form->addFormRule(array(&$this, 'checkLogin'));
     // Process the form
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues());
     } else {
         $form->display();
     }
 }
 function actionDefault()
 {
     // create form
     $form = new YDForm('myform');
     // add elements
     $form->addElement('text', 'txt', 'Enter your name:');
     $form->addElement('captcha', 'cap', 'Enter code:');
     $form->addElement('submit', 'cmd', 'Send');
     // add rules
     $form->addRule('txt', 'required', 'Your name is required');
     $form->addRule('cap', 'captcha', 'Security code is not valid');
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
 }
Exemplo n.º 17
0
 function actionDefault()
 {
     // Get the list of files and file sizes
     $cache_pub_lbl = 'Public cache ' . $this->_getTotalSizeAndCountAsText(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX);
     $cache_tmb_lbl = 'Thumbnail cache ' . $this->_getTotalSizeAndCountAsText(YD_TMP_PRE . 'N_*.*');
     $cache_web_lbl = 'Web download cache ' . $this->_getTotalSizeAndCountAsText('*.wch');
     $cache_tpl_lbl = 'Template cache ' . $this->_getTotalSizeAndCountAsText('*.tpl.php');
     // Create the delete form
     $form = new YDForm('clearCacheForm');
     $form->addElement('checkbox', 'cache_pub', $cache_pub_lbl, array('style' => 'border: none;'));
     $form->addElement('checkbox', 'cache_tmb', $cache_tmb_lbl, array('style' => 'border: none;'));
     $form->addElement('checkbox', 'cache_web', $cache_web_lbl, array('style' => 'border: none;'));
     $form->addElement('checkbox', 'cache_tpl', $cache_tpl_lbl, array('style' => 'border: none;'));
     $form->addElement('submit', '_cmdSubmit', t('cleanup'), array('class' => 'button'));
     $form->setDefaults(array('cache_pub' => 1, 'cache_web' => 1, 'cache_tmb' => 1, 'cache_tpl' => 1));
     // Validate the form
     if ($form->validate() == true) {
         // Check if we need to delete the thumbnail objects
         if ($form->getValue('cache_pub')) {
             $this->_deleteCacheFiles(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX);
         }
         // Check if we need to delete the thumbnail objects
         if ($form->getValue('cache_tmb') == 1) {
             $this->_deleteCacheFiles(YD_TMP_PRE . 'N_*.*');
         }
         // Check if we need to delete the web objects
         if ($form->getValue('cache_web')) {
             $this->_deleteCacheFiles('*.wch');
         }
         // Check if we need to delete the template objects
         if ($form->getValue('cache_tpl')) {
             $this->_deleteCacheFiles('*.tpl.php');
         }
         // Add a status message
         $this->tpl->assign('message', t('cache_cleaned_up'));
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
Exemplo n.º 18
0
 function actionDefault()
 {
     // Set the title of the form
     $this->template->assign('title', 'Sample form');
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('firstForm');
     // Set the defaults
     $form->setDefaults(array('name' => 'Joe User'));
     // Add the elements
     $form->addElement('text', 'name', 'Enter your name:', array('size' => 50));
     $form->addElement('bbtextarea', 'desc1', 'Enter the description:');
     $form->addElement('bbtextarea', 'desc2', 'Enter the description (no toolbar):');
     $form->addElement('bbtextarea', 'desc3', 'Enter the description:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Update the no toolbar element
     $element =& $form->getElement('desc2');
     $element->clearButtons();
     // Add a popup window to the third description
     $element =& $form->getElement('desc3');
     $element->addPopupWindow('form.php?do=selector&field=firstForm_desc3&tag=img', 'select image');
     $element->addPopupWindow('form.php?do=selector&field=firstForm_desc3&tag=url', 'select url');
     // Apply a filter
     $form->addFilter('name', 'trim');
     $form->addFilter('desc1', 'safe_html');
     // Add a rule
     $form->addRule('name', 'required', 'Please enter your name');
     // Process the form
     if ($form->validate()) {
         // Show the form values
         YDDebugUtil::dump($form->getValues());
         // Mark the form as valid
         $this->template->assign('formValid', true);
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
Exemplo n.º 19
0
 function actionDefault()
 {
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     //$form->addRule( 'file1', 'maxlength', 'Path can only be 8 characters', 8 );
     $form->addRule('file1', 'maxfilesize', 'Maximum filesize of 1000 KB is exceeded!', 1000 * 1024);
     //$form->addRule( 'file1', 'extension', 'File extension should be txt!', 'txt' );
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             // You may fetch the name before the file hits the FS
             $temp_filename = $file->getBaseName();
             // Move the upload
             $file->moveUpload('./tmp');
             //$file->moveUpload( './tmp', 'TEST_' . $temp_filename );
             //$file->moveUpload( './tmp', md5(time()) );
             //$file->moveUpload( './tmp', md5(time()), true );
             // Mark the form as valid
             $this->template->assign('formValid', true);
             // Display file information
             $this->template->assign('filename', $file->getBaseName());
             $this->template->assign('filesize', $file->getSize());
             $this->template->assign('ext', $file->getExtension());
             $this->template->assign('path', $file->getPath());
         }
     }
     // Add the form to the template
     $this->template->assign('form_html', $form->toHtml());
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
Exemplo n.º 20
0
 function actionDefault()
 {
     // Mark the form as not valid
     $this->setVar('formValid', false);
     // Create the form
     $form = new YDForm('emailForm');
     // Add the elements
     $form->addElement('text', 'email', 'Enter your email address:', array('style' => 'width: 300px;'));
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Apply a filter
     $form->addFilter('email', 'trim');
     // Add a rule
     $form->addRule('email', 'email', 'Please enter a valid email address');
     // Process the form
     if ($form->validate()) {
         // Mark the form as valid
         $this->setVar('formValid', true);
         // Parse the template for the email
         $emlTpl = new YDTemplate();
         $emlTpl->setVar('email', $form->getValue('email'));
         $body = $emlTpl->getOutput('email_template');
         // Send the email
         $eml = new YDEmail();
         $eml->setFrom('*****@*****.**', YD_FW_NAME);
         $eml->addTo($form->getValue('email'), 'Yellow Duck');
         $eml->setSubject('Hello from Pieter & Fiona!');
         $eml->setHtmlBody($body);
         $eml->addAttachment('email.tpl');
         $eml->addHtmlImage('fsimage.jpg', 'image/jpeg');
         $result = $eml->send();
         // Add the result
         $this->setVar('result', $result);
     }
     // Add the form to the template
     $this->setVar('form_html', $form->toHtml());
     $this->addForm('form', $form);
     // Output the template
     $this->outputTemplate();
 }
 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     // Add elements
     $form->addElement('text', 'username', 'Fill a username that starts with spaces');
     $form->addElement('text', 'name', 'Fill a small caps name');
     $form->addElement('datetimeselect', 'date1', 'Date1');
     $form->addElement('date', 'date2', 'Date2');
     $form->addElement('datetimeselect', 'date3', 'Date3');
     $form->addElement('datetimeselect', 'date4', 'Date4');
     $form->addElement('submit', '_cmdSubmit', 'Submit');
     // Some defaults
     $form->setDefault('username', '    myuser');
     $form->setDefault('name', 'igor');
     // Add filters
     $form->addFilter('username', 'trim');
     // must return eg 'myuser'
     $form->addFilter('name', 'upper');
     // must return eg 'IGOR'
     if ($form->validate()) {
         // IMPORTANT NOTE: 'dateformat' filters must be always added AFTER form validation !
         // On form validation checking (by $form->validate()), 'dateformat' filter is applyed and
         // element is not populated again because date result array is lost.
         // This is why form is not displayed correctly after validation
         // (if some rule is broken you would not get the date element with correct values)
         $form->addFilter('date2', 'dateformat', 'day');
         // must return eg '20'
         $form->addFilter('date3', 'dateformat', 'datetimesql');
         // must return eg '2005-02-01 10:00:00'
         $form->addFilter('date4', 'dateformat', "%b");
         // must return eg 'Aug'
         YDDebugUtil::dump($form->getValues(), '$form->getValues()');
     } else {
         // Display form
         $form->display();
     }
 }
 /**
  *  This action takes care of handling the login form. It can show and validate a login form and redirects to
  *  default action of the request class when the user is authenticated.
  */
 function actionLogin()
 {
     // Redirect to default action if already logged in
     if ($this->isAuthenticated() === true) {
         $this->forward('default');
         return;
     }
     // Create the login form
     $form = new YDForm('loginForm');
     $form->addElement('text', 'loginName', t('username'), array('class' => 'tfL'));
     $form->addElement('password', 'loginPass', t('password'), array('class' => 'tfL'));
     $form->addElement('checkbox', 'loginRememberMe', t('remember_me'));
     $form->addElement('submit', 'cmdSubmit', 'Login', array('class' => 'button'));
     $form->setDefault('loginRememberMe', true);
     // Add the rules
     $form->addFormRule(array(&$this, 'checkLogin'));
     // Process the form
     if ($form->validate()) {
         // Get the form values
         $values = $form->getValues();
         // Update the password
         $values['loginPass'] = md5($values['loginPass']);
         // Set the cookies
         if ($values['loginRememberMe'] === 1) {
             $this->setCookie($this->cookieNameUser, $values['loginName'], false);
             $this->setCookie($this->cookieNamePass, $values['loginPass'], false);
         } else {
             $this->setCookie($this->cookieNameUser, $values['loginName'], true);
             $this->setCookie($this->cookieNamePass, $values['loginPass'], true);
         }
         // Forward to the main manage page
         $this->redirectToAction();
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Output the template
     $this->tpl->displayWithMaster('login');
 }
Exemplo n.º 23
0
 function actionEditPost()
 {
     if (!isset($_GET['idPost'])) {
         $this->errorRequete();
         return;
     }
     if ($this->user->authentificated) {
         $postlogic = new PostsLogic();
         $post = $postlogic->retrievePostById($_GET['idPost']);
         if ($post != null) {
             if ($this->user->rightslevel >= LEVEL_MODERATOR || $this->user->id == $post->idAuthor) {
                 // Create the add post form
                 $form = new YDForm('postEdit');
                 $form->addElement('hidden', 'idPost', $post->id);
                 $form->addElement('text', 'postTitle', t('posts.messagetitle'), array("size" => 60));
                 $form->addElement('textarea', 'postContent', t('posts.message'), array("cols" => 50, "rows" => 8));
                 $form->addElement('submit', 'cmdSubmit', t('posts.editmessage'));
                 // Add rules
                 $form->addFormRule(array(&$this, 'simpleCheckPost'));
                 // Process the form
                 if ($form->validate()) {
                     $post->title = $form->getValue('postTitle');
                     $post->content = $form->getValue('postContent');
                     $post->idEditor = $this->user->id;
                     $post->ipEditor = $this->user->ip;
                     $post->dateEdited = date('Y-m-d H:i:s', mktime());
                     $post->update();
                     // on redirige sur le post parent si il existe
                     if ($post->idPostParent != null) {
                         $postParent = $postlogic->retrievePostById($post->idPostParent);
                         $postParent->dateAnswer = date('Y-m-d H:i:s', mktime());
                         $postParent->update();
                         $this->actionTpl->assign('post', $postParent);
                     } else {
                         $this->actionTpl->assign('post', $post);
                     }
                     $this->actionTpl->assign('editMessage', true);
                     // we are editing the message
                     $content = new page($this->actionTpl->fetch('templates/posts.success.tpl'), t('posts.updsuccess'));
                     $this->display($content);
                     return;
                 }
                 $form->setDefaults(array('postTitle' => $post->title));
                 $form->setDefaults(array('postContent' => $post->content));
                 // Assign variables to the template
                 $this->actionTpl->assign('form', $form->toArray());
                 // forms
                 $this->actionTpl->assign('user', $this->user);
                 // user for rights
                 $this->actionTpl->assign('editMessage', true);
                 // we are editing the message
                 $content = new page($this->actionTpl->fetch('templates/posts.new.tpl'), t('posts.messageupdate'));
                 $this->display($content);
                 return;
             } else {
                 $this->errorRequete(t('posts.notrightupdate'));
                 return;
             }
         } else {
             $this->errorRequete(t('posts.donotexists'));
             return;
         }
     } else {
         $content = new page($this->actionTpl->fetch('templates/user.notAuth.tpl'), t('global.notconnected'));
     }
 }
Exemplo n.º 24
0
 function actionManageForums()
 {
     // Create the addForum form
     $form = new YDForm('forumForm');
     $form->addElement('text', 'forumTitle', t('admin.newforumtitle'), array("size" => 40));
     $form->addElement('text', 'forumPoids', t('admin.forumweightorder'), array());
     $form->addElement('submit', 'cmdSubmit', t('admin.forumcreate'));
     // Add rules
     $form->addFormRule(array(&$this, 'checkNewForum'));
     $form->addRule('forumPoids', 'numeric', t('admin.forumweightinteger'));
     // Process the form
     if ($form->validate()) {
         // get and show results
         $forum = new ForumObject($form->getValue('forumTitle'), $form->getValue('forumPoids'));
         $forum->insert();
     }
     // Future defaults values
     $form->setDefaults(array('forumTitle' => ''));
     $form->setDefaults(array('forumPoids' => ''));
     // retrieve existing forums
     $forumLogic = new ForumsLogic();
     $forums = $forumLogic->retrieveAllByOrderSimple();
     // Assign variables to the template
     $this->actionTpl->assign('form', $form->toArray());
     $this->actionTpl->assign('forums', $forums);
     $content = new Page($this->actionTpl->fetch('templates/admin.forums.list.tpl'), t('admin.manageforums'), $this->menusAdmin);
     // Display the action template into the master template
     $this->display($content);
 }
Exemplo n.º 25
0
 function actionDefault()
 {
     // Check for the config file
     if (is_file(dirname(__FILE__) . '/include/config.php')) {
         $this->redirectToAction('error');
     }
     // Get the list of skins
     $dir = new YDFSDirectory(dirname(__FILE__) . '/' . $this->dir_skins);
     $items = $dir->getContents('!.*', '', array('YDFSDirectory'));
     $skins = array();
     foreach ($items as $item) {
         $skins[$item] = $item;
     }
     // Get the list of languages
     $dir = new YDFSDirectory(dirname(__FILE__) . '/include/languages/');
     $items = $dir->getContents('language_*.php', '', array('YDFSFile'));
     $languages = array();
     foreach ($items as $item) {
         $item = substr($item, 9, -4);
         $languages[$item] = $item;
     }
     // Create the configuration form
     $form = new YDForm('configForm');
     // Add the fields
     $form->addElement('text', 'db_host', 'Database host', array('class' => 'tfM'));
     $form->addElement('text', 'db_name', 'Database name', array('class' => 'tfM'));
     $form->addElement('text', 'db_user', 'Database user', array('class' => 'tfM'));
     $form->addElement('password', 'db_pass', 'Database password', array('class' => 'tfM'));
     $form->addElement('text', 'db_prefix', 'Database table prefix', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', 'Weblog title', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_description', 'Weblog description', array('class' => 'tfM'));
     $form->addElement('select', 'weblog_skin', 'Weblog skin', array('class' => 'tfM', 'style' => 'width: 100%'), $skins);
     $form->addElement('select', 'weblog_language', 'Weblog language', array('class' => 'tfM', 'style' => 'width: 100%'), $languages);
     $form->addElement('text', 'name', 'User name', array('class' => 'tfM'));
     $form->addElement('text', 'email', 'User email', array('class' => 'tfM'));
     $form->addElement('password', 'password', 'Password', array('class' => 'tfM'));
     $form->addElement('submit', '_cmdSubmit', 'Install', array('class' => 'button'));
     // Add the rules
     $form->addRule('db_host', 'required', 'Database host is required');
     $form->addRule('db_name', 'required', 'Database name is required');
     $form->addRule('db_user', 'required', 'Database user is required');
     $form->addRule('weblog_title', 'required', 'Weblog title is required');
     $form->addRule('name', 'required', 'User name is required');
     $form->addRule('email', 'email', 'User email is required');
     $form->addRule('password', 'required', 'Password is required');
     $form->addFormRule(array(&$this, 'checkInstallParams'));
     // Set the defaults
     $form->setDefault('db_host', 'localhost');
     $form->setDefault('db_name', 'ydweblog');
     $form->setDefault('db_user', 'root');
     $form->setDefault('db_prefix', 'ydw_');
     $form->setDefault('weblog_title', 'My Weblog');
     $form->setDefault('weblog_description', 'Description of my Weblog');
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Connect to the database
         $db = YDDatabase::getInstance('mysql', $values['db_name'], $values['db_user'], $values['db_pass'], $values['db_host']);
         // Create the tables
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'categories;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'categories ( id int(11) NOT NULL auto_increment, title varchar(255) NOT NULL default \'\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY  (id) ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'comments;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'comments (
                   id int(11) NOT NULL auto_increment,
                   item_id int(11) NOT NULL default \'1\',
                   username varchar(255) NOT NULL default \'\',
                   useremail varchar(255) NOT NULL default \'\',
                   userwebsite varchar(255) default NULL,
                   userip varchar(20) default NULL,
                   comment longtext NOT NULL,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY item_id (item_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'items;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'items (
                   id int(11) NOT NULL auto_increment,
                   category_id int(11) default \'1\',
                   user_id int(11) NOT NULL default \'1\',
                   title varchar(255) NOT NULL default \'\',
                   body longtext NOT NULL,
                   body_more longtext NOT NULL,
                   num_comments int(11) NOT NULL default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY category_id (category_id),
                   KEY user_id (user_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'links;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'links (
                   id int(11) NOT NULL auto_increment,
                   title varchar(255) NOT NULL default \'\',
                   url varchar(255) NOT NULL default \'\',
                   num_visits int(11) default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   UNIQUE KEY url (url)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'pages;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'pages (
                   id int(11) NOT NULL auto_increment,
                   user_id int(11) NOT NULL default \'1\',
                   title varchar(255) NOT NULL default \'\',
                   body longtext,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY user_id (user_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics (
                   id int(11) NOT NULL auto_increment,
                   date date NOT NULL default \'0000-00-00\',
                   uri varchar(255) NOT NULL default \'0\',
                   browser varchar(10) NOT NULL default \'\',
                   platform varchar(10) NOT NULL default \'\',
                   hits int(11) NOT NULL default \'0\',
                   PRIMARY KEY  (id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics_init;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics_init (
                   created varchar(10) NOT NULL default \'\'
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'users;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'users (
                   id int(11) NOT NULL auto_increment,
                   name varchar(255) NOT NULL default \'\',
                   email varchar(255) NOT NULL default \'\',
                   password varchar(50) default NULL,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   UNIQUE KEY email (email)
                 ) TYPE=MyISAM;');
         $db->executeInsert($values['db_prefix'] . 'statistics_init', array('created' => $db->getDate('__NOW__')));
         // Include the weblog API
         YDInclude(dirname(__FILE__) . '/include/YDWeblogAPI.php');
         // Save the config file
         YDWeblogSaveConfig($values);
         // Include the config file
         YDInclude(dirname(__FILE__) . '/include/config.php');
         // Create the weblog object
         $weblog = new YDWeblogAPI();
         // Add the user
         $user = array();
         $user['name'] = $values['name'];
         $user['email'] = $values['email'];
         $user['password'] = $values['password'];
         $weblog->saveUser($user);
         // Add a category
         $category = array();
         $category['title'] = 'General';
         $weblog->addCategory($category);
         // Create a first post
         $item = array();
         $item['category_id'] = 1;
         $item['user_id'] = 1;
         $item['title'] = 'Your first post';
         $item['body'] = 'Welcome to your weblog';
         $item['body_more'] = 'Your extended body';
         $weblog->addItem($item);
         // Create a second post
         $item = array();
         $item['category_id'] = 1;
         $item['user_id'] = 1;
         $item['title'] = 'Your second post';
         $item['body'] = 'Without an extended body';
         $item['created'] = time() + 100;
         $weblog->addItem($item);
         // Add a comment
         $comment = array();
         $comment['item_id'] = 1;
         $comment['username'] = '******';
         $comment['useremail'] = '*****@*****.**';
         $comment['userwebsite'] = YD_FW_HOMEPAGE;
         $comment['comment'] = 'A first comment';
         $weblog->addComment($comment);
         // Add a sample page
         $page = array();
         $page['user_id'] = 1;
         $page['title'] = 'Your first page';
         $page['body'] = 'The contents of your first page';
         $weblog->addPage($page);
         // Add a link
         $link = array();
         $link['title'] = 'Yellow Duck Framework';
         $link['url'] = 'http://ydframework.berlios.de/';
         $weblog->addLink($link);
         // Redirect to the finish action
         $this->redirectToAction('finish');
     }
     // Add it to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->tpl->display();
 }
Exemplo n.º 26
0
 function actionLogin()
 {
     // Redirect to default action if already logged in
     if ($this->isAuthenticated() === true) {
         $this->forward('default');
         return;
     }
     // Create the login form
     $form = new YDForm('loginForm');
     $form->addElement('text', 'loginName', t('user.login'));
     $form->addElement('password', 'loginPass', t('user.pwd'));
     $form->addElement('submit', 'cmdSubmit', 'Login');
     $form->setDefaults(array('loginPass' => ''));
     // Add the rules
     $form->addFormRule(array(&$this, 'checkLogin'));
     // Process the form
     if ($form->validate()) {
         // Mark the form as valid
         $this->authenticationSucceeded();
         header('location: forums.php');
         return;
     }
     // Assign variables to the action template
     $this->actionTpl->assign('form', $form->toArray());
     $content = new Page($this->actionTpl->fetch('templates/user.login.tpl'), '');
     // Display the action template into the master template
     $this->display($content);
 }
Exemplo n.º 27
0
 function actionSuscribe()
 {
     if (!$this->user->authentificated) {
         // Create the profile form
         $form = new YDForm('suscribeForm');
         $form->addElement('text', 'suscribeLogin', t('user.login'));
         $form->addElement('textarea', 'suscribeDescription', t('user.desc'));
         $form->addElement('password', 'suscribePassUn', t('user.pwd'));
         $form->addElement('password', 'suscribePassDeux', t('user.confirmpwd'));
         $form->addElement('submit', 'cmdSubmit', t('user.valid'));
         // Add rules
         $form->addFormRule(array(&$this, 'checkSuscribe'));
         // Process the form
         if ($form->validate()) {
             // Insert profile
             $this->user->id = '';
             $this->user->login = $form->getValue('suscribeLogin');
             $this->user->description = $form->getValue('suscribeDescription');
             $this->user->password = md5($form->getValue('suscribePassUn'));
             $this->user->insert();
             $this->user->auth();
             $_GET['idUser'] = $this->user->id;
             $_SESSION['s_user'] = YDObjectUtil::serialize($this->user);
             // Redirect sur les forums
             header('location: forums.php');
             return;
         }
         // Assign variables to the template
         $this->actionTpl->assign('form', $form->toArray());
         $content = new page($this->actionTpl->fetch('templates/user.suscribe.tpl'), 'Inscription');
         // Display the action template into the master template
         $this->display($content);
     } else {
         $this->actionMonProfil();
         return;
     }
 }