Пример #1
0
 public function __construct()
 {
     parent::__construct('all_categories');
     if ($this->loginError) {
         return;
     }
     $cat_list = pdCatList::create($this->db);
     echo '<h1>Publication Categories</h1>';
     foreach (array_keys($cat_list) as $cat_id) {
         unset($fields);
         unset($cells);
         $category = new pdCategory();
         $result = $category->dbLoad($this->db, $cat_id);
         assert('$result');
         $table = new HTML_Table(array('class' => 'publist'));
         $table->setAutoGrow(true);
         $cells[] = '<b>' . $category->category . '</b><br/>';
         if (count($category->info) > 0) {
             foreach ($category->info as $info_id => $name) {
                 $fields[] = $name;
             }
             $cells[] = 'Fields: ' . implode(', ', $fields);
         } else {
             $cells[] = '';
         }
         if ($this->access_level > 0) {
             $cells[] = $this->getCategoryIcons($category);
         }
         $table->addRow($cells);
         $table->updateColAttributes(0, array('class' => 'category'), NULL);
         $table->updateColAttributes(2, array('class' => 'icons'), NULL);
         echo $table->toHtml();
         unset($table);
     }
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct('delete_category', 'Delete Category', 'Admin/delete_category.php');
     if ($this->loginError) {
         return;
     }
     $this->loadHttpVars();
     if (!isset($this->cat_id)) {
         echo 'No category id defined';
         $this->pageError = true;
         return;
     } else {
         if (!is_numeric($this->cat_id)) {
             $this->pageError = true;
             return;
         }
     }
     $category = new pdCategory();
     $result = $category->dbLoad($this->db, $this->cat_id);
     if (!$result) {
         $this->pageError = true;
         return;
     }
     $pub_list = pdPubList::create($this->db, array('cat_id' => $this->cat_id));
     if (isset($pub_list) && count($pub_list) > 0) {
         echo 'Cannot delete category <b>', $category->category, '</b>.<p/>', 'The category is used by the following publications:', "\n", displayPubList($this->db, $pub_list);
         return;
     }
     $form =& $this->confirmForm('deleter');
     $form->addElement('hidden', 'cat_id', $this->cat_id);
     $renderer =& $form->defaultRenderer();
     $form->accept($renderer);
     if ($form->validate()) {
         $values = $form->exportValues();
         // This is where the actual deletion happens.
         $category->dbDelete($this->db);
         echo 'Category <b>', $category->category, '</b> removed from the database.';
     } else {
         echo '<h3>Confirm</h3>Delete category <b>', $category->category, '</b>?<p/>';
         $this->form =& $form;
         $this->renderer =& $renderer;
     }
 }
Пример #3
0
 public function __construct()
 {
     parent::__construct('add_category');
     $this->loadHttpVars();
     if ($this->loginError) {
         return;
     }
     $category = new pdCategory();
     if (isset($this->cat_id)) {
         if (!is_numeric($this->cat_id)) {
             $this->pageError = true;
             return;
         }
         $result = $category->dbLoad($this->db, $this->cat_id);
         if (!$result) {
             $this->pageError = true;
             return;
         }
     }
     if (isset($this->numNewFields)) {
         if (!is_numeric($this->numNewFields)) {
             $this->pageError = true;
             return;
         }
     } else {
         $this->numNewFields = 0;
     }
     if ($category->cat_id != '') {
         $label = 'Edit Category';
     } else {
         $label = 'Add Category';
     }
     $this->pageTitle = $label;
     $form = new HTML_QuickForm('catForm');
     $form->addElement('header', null, $this->helpTooltip($label, 'addCategoryPageHelp', 'helpHeading'));
     $form->addElement('text', 'catname', 'Category Name:', array('size' => 50, 'maxlength' => 250));
     $form->addRule('catname', 'category name cannot be empty', 'required', null, 'client');
     // info list
     $label = 'Related Fields:';
     $info_list = pdInfoList::create($this->db);
     foreach ($info_list as $info_id => $name) {
         $form->addElement('advcheckbox', 'info[' . $info_id . ']', $label, $name, null, array('', $name));
         $label = '';
     }
     for ($i = 0; $i < $this->numNewFields; $i++) {
         $form->addElement('text', 'new_fields[' . $i . ']', 'New field ' . ($i + 1) . ':', array('size' => 50, 'maxlength' => 250));
     }
     $form->addElement('hidden', 'numNewFields', $this->numNewFields);
     $form->addGroup(array(HTML_QuickForm::createElement('reset', 'reset', 'Reset'), HTML_QuickForm::createElement('button', 'add_field', 'Add Related Field', array('onClick' => 'dataKeep(' . ($this->numNewFields + 1) . ');')), HTML_QuickForm::createElement('submit', 'submit', 'Submit New Category')), 'submit_group', null, '&nbsp;');
     if ($form->validate()) {
         $values = $form->exportValues();
         $category->category = $values['catname'];
         if (isset($values['new_fields'])) {
             $values['info'] = array_merge($values['info'], $values['new_fields']);
         }
         foreach ($values['info'] as $infoname) {
             if ($infoname == '') {
                 continue;
             }
             $obj = new stdClass();
             $obj->name = $infoname;
             $category->info[] = $obj;
         }
         $category->dbSave($this->db);
         echo 'Category "', $category->category, '" succesfully added to the database.', '<p/>', '<a href="' . $_SERVER['PHP_SELF'] . '">', 'Add another new category</a>';
     } else {
         foreach (array_keys(get_class_vars(get_class($this))) as $member) {
             $defaults[$member] = $this->{$member};
         }
         $defaults['catname'] = $category->category;
         if (isset($category->info) && count($category->info) > 0) {
             foreach ($category->info as $info_id => $name) {
                 $defaults['info[' . $info_id . ']'] = $name;
             }
         }
         $form->setDefaults($defaults);
         $renderer =& $form->defaultRenderer();
         $form->accept($renderer);
         $this->form =& $form;
         $this->renderer =& $renderer;
         $this->javascript();
     }
 }