News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1284322976:v:use_geshi-1:v:type-php

Started by SleePy, Sep 12, 2010, 08:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

class SmcController_manageType extends SmcController
{
   protected $_typeForm;
   protected $action;

   public function initialize()
   {
      global $siteman_settings;

      require_once($siteman_settings['sourcedir'] . '/Subs-SiteMan-Type.php');

      // Sorry, we shouldn't let too many people change the types.  We don't modify this that often.
      siteman_isAllowedTo('admin_siteman');
   }

   public function action_index()
   {
      // Default to sa=display.
      return $this->action_display();
   }

   public function action_display()
   {
      $id_type = isset($_GET['id_type']) ? (int) $_GET['id_type'] : 0;
      $version_info = gettypeInfo($id_type);

      $this->_inittypeForm();
      $this->_typeForm->handleAction('display');
   }

   public function action_edit()
   {
      $id_type = isset($_GET['id_type']) ? (int) $_GET['id_type'] : 0;

      $type_info = gettypeInfo($id_type);

      $this->_inittypeForm();
      $this->_typeForm->handleAction('edit');
   }

   public function action_add()
   {
      $this->_inittypeForm();
      $this->action = 'add';
      $this->_typeForm->handleAction('add');
   }

   protected function _inittypeForm()
   {
      global $siteman_settings;

      require_once($siteman_settings['sourcedir'] . '/Class-Form.php');

      $this->_typeForm = new SmcForm(array(
         'id' => 'manageType',
         'params' => array(
            'action' => 'string',
            'sa' => 'string',
            'id_type' => 'int',

         ),
         'actions' => array(
            'add' => array(
               'label' => 'Add a Type',
               'scripturl' => $siteman_settings['scripturl'],
               'controls' => array(
                  'name',
               ),
               'submit_function' => array($this, 'form_manageType_add_submit'),
               'redirect_href' => $siteman_settings['scripturl'] . '?action=manageType;sa=edit;id_type={id_type};refresh_tree=r_mb_eb:{id_type}',
            ),
            'edit' => array(
               'label' => 'Edit Type {type_name}',
               'scripturl' => $siteman_settings['scripturl'],
               'retrieve_function' => array($this, 'form_manageType_edit_retrieve'),
               'submit_function' => array($this, 'form_manageType_edit_submit'),
               'redirect_href' => $siteman_settings['scripturl'] . '?action=manageType;id_type={id_type};refresh_tree=r_mb_eb:{id_type}',
            ),
            'display' => array(
               'label' => 'Type {type_name}',
               'scripturl' => $siteman_settings['scripturl'],
               'read_only_controls' => array(
                  'name',
               ),
               'retrieve_function' => array($this, 'form_manageType_display_retrieve'),
               'tabs' => array(
                  'edit' => array(
                     'href' => $siteman_settings['scripturl'] . '?action=manageType;sa=edit;id_type={id_type}',
                     'label' => 'Edit Type',
                  ),
               ),
            ),

         ),
         'controls' => array(
            'name' => array(
               'label' => 'Type name',
               'edit_hint' => 'e.g. \'Converters\'',
               'type' => 'text',
               'validation' => array(
                  'isRequired' => true,
               ),
            ),
         ),
      ));
   }

   public function form_manageType_add_submit($form, $submittedValues)
   {
      $id_type = addType($submittedValues);
      $form->updateParam('id_type', $id_type);
   }

   public function form_manageType_edit_retrieve($form)
   {
      return getTypeInfo($form->params['id_type']);
   }

   public function form_manageType_edit_submit($form, $submittedValues)
   {
      editType($form->params['id_type'], $submittedValues);
   }

   public function form_manageType_display_retrieve($form)
   {
      return getTypeInfo($form->params['id_type']);
   }
}
No siggy! :D