Ejemplo n.º 1
0
 /**
  *  Helper method for user management
  *
  * @param $id           If you will EDIT some user this is the user id to edit.
  *                      If you will ADD a new user this is the group id (parent_id) of the new user.
  * @param $edit         The edit parameter. TRUE if form is form editing, FALSE if form is for a new user creation
  * @param $noneditable  Array with form element names that are NOT editable
  *
  * @returns    YDForm object pointer         
  */
 function &_addFormDetails($id, $edit, $noneditable)
 {
     YDInclude('YDForm.php');
     // init form
     $this->_form = new YDForm('YDCMUsers');
     // check arguments
     if (!is_array($noneditable)) {
         $noneditable = array($noneditable);
     }
     // add username
     if (in_array('username', $noneditable)) {
         $this->_form->addElement('span', 'username', t('ydcmuser label username'));
     } else {
         $this->_form->addElement('text', 'username', t('ydcmuser label username'));
         $this->_form->addFormRule(array(&$this, '_checkuser'), array($edit, $id));
     }
     // add password box for new users
     if ($edit == false) {
         $this->_form->addElement('password', 'password', t('ydcmuser label password'));
         $this->_form->addElement('password', 'password2', t('ydcmuser label password2'));
     }
     // add state
     if (in_array('state', $noneditable)) {
         $this->_form->addElement('span', 'state', t('ydcmuser label state'));
         $this->_form->addElement('span', 'login_start', t('ydcmuser label login_start'));
         $this->_form->addElement('span', 'login_end', t('ydcmuser label login_end'));
     } else {
         $this->_form->addElement('select', 'state', t('ydcmuser label state'), array(), array(1 => t('yes'), 0 => t('no'), 2 => t('schedule')));
         $this->_form->addElement('datetimeselect', 'login_start', t('ydcmuser label login_start'));
         $this->_form->addElement('datetimeselect', 'login_end', t('ydcmuser label login_end'));
     }
     // add common user details
     if (in_array('details', $noneditable)) {
         $this->_form->addElement('span', 'name', t('ydcmuser label name'));
         $this->_form->addElement('span', 'email', t('ydcmuser label email'));
         $this->_form->addElement('span', 'other', t('ydcmuser label other'));
         $this->_form->addElement('span', 'lang_id', t('ydcmuser label language'));
         $this->_form->addElement('span', 'template', t('ydcmuser label template'));
     } else {
         $this->_form->addElement('text', 'name', t('ydcmuser label name'), array('size' => 50, 'maxlength' => 255));
         $this->_form->addElement('text', 'email', t('ydcmuser label email'));
         $this->_form->addElement('textarea', 'other', t('ydcmuser label other'), array('rows' => 15, 'cols' => 40));
         $languages = new YDCMLanguages();
         $languages = $languages->active();
         $this->_form->addElement('select', 'lang_id', t('ydcmuser label language'), array(), $languages);
         $templates = YDCMTemplates::getNames();
         // get url to templates and set shot.png as filename
         $attributes = array('border' => 1, 'src' => YDConfig::get('YDCMTEMPLATES_ADMIN_URL'), 'ext' => YDConfig::get('YDCMTEMPLATES_ADMIN_EXT'));
         $this->_form->addElement('selectimage', 'template', t('ydcmuser label template'), $attributes, $templates);
         $this->_form->addRule('name', 'maxlength', t('ydcmuser mess name too big'), 255);
         $this->_form->addRule('email', 'email', t('ydcmuser mess email not valid'));
         $this->_form->addRule('other', 'maxlength', t('ydcmuser mess other too big'), 5000);
         $this->_form->addRule('language_id', 'in_array', t('ydcmuser mess language not valid'), array_keys($languages));
         $this->_form->addRule('template', 'in_array', t('ydcmuser mess template not valid'), array_keys($templates));
     }
     // add access information when editing
     if ($edit) {
         $this->_form->addElement('span', 'login_counter', t('ydcmuser label login_counter'));
         $this->_form->addElement('span', 'login_last', t('ydcmuser label login_last'));
         $this->_form->addElement('span', 'login_current', t('ydcmuser label login_current'));
     }
     // if we are editing a user it's a good idea to set form defaults with user node attributes
     if ($edit) {
         // add submit button
         $this->_form->addElement('submit', '_cmdSubmit', t('ydcmuser label save'));
         // set form defaults based on user attributes
         $this->_form->setDefaults($this->getUser($id));
     } else {
         // if id argument is not set its because we want a select box (with groups) so choose
         if (is_null($id)) {
             // get groups from userobject
             $obj = new YDCMUserobject();
             $this->_form->addElement('select', 'group', t('ydcmuser label group'), array(), $obj->getElements('YDCMGroup', 'reference'));
         }
         // add submit button
         $this->_form->addElement('submit', '_cmdSubmit', t('ydcmuser label new'));
         // when adding a user, if login_end date exists we setup 7 days interval
         if ($this->_form->isElement('login_end')) {
             $this->_form->setDefault('login_end', time() + 7 * 24 * 3600);
         }
     }
     return $this->_form;
 }
 /**
  *  This function returns all possible templates for visitors side
  *
  *  @returns    Associative array of templates, eg: array( 'Default' => 'Default', 'orange' => ... )
  */
 function visitors_templates()
 {
     return YDCMTemplates::__getFiles(YDConfig::get('YDCMTEMPLATES_VISITORS_PATH'));
 }