public function form() { javascript('jquery'); javascriptMod('properties', 'generate'); \Layout::addStyle('properties', 'forms.css'); $form = new \PHPWS_Form('contact'); $form->addHidden('module', 'properties'); if (!empty($this->id)) { $form->addHidden('cid', $this->id); $form->addSubmit('Update contact'); } else { $form->addSubmit('Add contact'); } if (isset($_SESSION['Contact_User']) && !\Current_User::allow('properties')) { $form->addHidden('cop', 'save_contact'); $form->addHidden('k', $_SESSION['Contact_User']->getKey()); } else { $form->addHidden('aop', 'save_contact'); $form->addText('username', $this->username); $form->setClass('username', 'form-control'); $form->setLabel('username', 'User name'); $form->setSize('username', '20', '20'); $form->setRequired('username'); $form->addButton('make_password', 'Create'); $form->setId('make_password', 'make-password'); $form->setClass('make_password', 'btn btn-default'); $form->addCheck('contact_contact', 1); $form->setLabel('contact_contact', 'Send contact email'); if (!$this->id) { $form->setMatch('contact_contact', 1); } } $form->addPassword('password'); $form->setLabel('password', 'Password'); $form->setClass('password', 'form-control'); $form->addPassword('pw_check'); $form->setLabel('pw_check', 'Retype password below'); $form->setClass('pw_check', 'form-control'); $form->addText('first_name', $this->first_name); $form->setLabel('first_name', 'Contact first name'); $form->setRequired('first_name'); $form->setClass('first_name', 'form-control'); $form->addText('last_name', $this->last_name); $form->setLabel('last_name', 'Contact last name'); $form->setRequired('last_name'); $form->setClass('last_name', 'form-control'); $form->addText('phone', $this->getPhone()); $form->setLabel('phone', 'Phone number'); $form->setRequired('phone'); $form->setClass('phone', 'form-control'); $form->addText('email_address', $this->email_address); $form->setLabel('email_address', 'Email address'); $form->setRequired('email_address'); $form->setSize('email_address', 40); $form->setClass('email_address', 'form-control'); $form->addText('company_name', $this->company_name); $form->setLabel('company_name', 'Company name'); $form->setRequired('company_name'); $form->setSize('company_name', 40); $form->setClass('company_name', 'form-control'); $form->addText('company_url', $this->company_url); $form->setLabel('company_url', 'Company url'); $form->setSize('company_url', 40); $form->setClass('company_url', 'form-control'); $form->addText('company_address', $this->company_address); $form->setLabel('company_address', 'Company (or renter) address'); $form->setClass('company_address', 'form-control'); $form->addTextArea('times_available', $this->times_available); $form->setLabel('times_available', 'Days and hours available for contact'); $form->setRows('times_available', 4); $form->setCols('times_available', 20); $form->setClass('times_available', 'form-control'); $tpl = $form->getTemplate(); if (!empty($this->errors)) { foreach ($this->errors as $key => $message) { $new_key = strtoupper($key) . '_ERROR'; $tpl[$new_key] = $message; } } return \PHPWS_Template::process($tpl, 'properties', 'edit_contact.tpl'); }
public function getSearchBox() { static $id_count = 0; if ($id_count) { $id = 'search_list_' . $id_count; } else { $id = 'search_list'; $id_count++; } $form = new PHPWS_Form($id); $form->setMethod('get'); $values = $this->getLinkValues(); unset($values['pager_search']); unset($values['go']); $form->addHidden($values); $form->addText('pager_c_search', $this->search); $form->setSize('pager_c_search', 20); if ($this->search_label) { $form->setLabel('pager_c_search', _('Search')); } if ($this->clear_button) { $form->addButton('clear', _('Clear')); $form->setExtra('clear', 'onclick="this.form.search_list_pager_c_search.value=\'\'"'); } if ($this->search_button) { $form->addSubmit('go', _('Search')); } $template = $form->getTemplate(); if (PHPWS_Error::isError($template)) { PHPWS_Error::log($template); return null; } return implode("\n", $template); }
public function jsStyleChange() { $styles = Layout::getExtraStyles(); if (empty($styles) || !isset($_REQUEST['key_id'])) { return false; } $styles[0] = dgettext('layout', '-- Use default style --'); ksort($styles, SORT_NUMERIC); $key_id = (int) $_REQUEST['key_id']; $current_style = Layout::getKeyStyle($key_id); if (empty($current_style)) { $current_style = 0; } $form = new PHPWS_Form('change_styles'); $form->addHidden('module', 'layout'); $form->addHidden('action', 'admin'); $form->addHidden('command', 'post_style_change'); $form->addHidden('key_id', $key_id); $form->addSelect('style', $styles); $form->setLabel('style', dgettext('layout', 'Style sheet')); $form->setMatch('style', $current_style); $form->addSubmit(dgettext('layout', 'Save')); $form->addButton('cancel', dgettext('layout', 'Cancel')); $form->setExtra('cancel', 'onclick="window.close()"'); $template = $form->getTemplate(); $template['TITLE'] = dgettext('layout', 'Change CSS'); return PHPWS_Template::process($template, 'layout', 'style_change.tpl'); }
public static function editFeed(RSS_Feed $feed) { $form = new PHPWS_Form(); if ($feed->id) { $form->addHidden('feed_id', $feed->id); } $form->addHidden('module', 'rss'); $form->addHidden('command', 'save_feed'); $form->addText('address', $feed->address); $form->setLabel('address', dgettext('rss', 'Address')); $form->setSize('address', '30'); $form->addText('title', $feed->title); $form->setLabel('title', dgettext('rss', 'Title')); $form->setSize('title', '30'); $form->addSubmit('submit', dgettext('rss', 'Save')); $form->addButton('cancel', dgettext('rss', 'Cancel')); $form->setExtra('cancel', 'onclick="window.close()"'); $form->addText('item_limit', $feed->item_limit); $form->setSize('item_limit', 2); $form->setLabel('item_limit', dgettext('rss', 'Item limit')); $form->addText('refresh_time', $feed->refresh_time); $form->setSize('refresh_time', 5); $form->setLabel('refresh_time', dgettext('rss', 'Refresh time')); $template = $form->getTemplate(); $template['TITLE_WARNING'] = dgettext('rss', 'Feed title will be used if left empty'); $template['REFRESH_WARNING'] = dgettext('rss', 'In seconds'); $content = PHPWS_Template::process($template, 'rss', 'add_feed.tpl'); $tpl['TITLE'] = dgettext('rss', 'Add Feed'); $tpl['CONTENT'] = $content; return $tpl; }
public static function userForm(PHPWS_User $user, $message = NULL) { javascript('jquery'); javascriptMod('users', 'generate'); $form = new PHPWS_Form('edit-user'); if ($user->getId() > 0) { $form->addHidden('user_id', $user->getId()); $form->addSubmit('go', dgettext('users', 'Update User')); } else { $form->addSubmit('go', dgettext('users', 'Add User')); } $form->addHidden('action', 'admin'); $form->addHidden('command', 'postUser'); $form->addHidden('module', 'users'); $form->addCheckbox('notify_user', 1); $form->setLabel('notify_user', dgettext('user', 'Notify user of account creation')); if (Current_User::allow('users', 'settings')) { $db = new PHPWS_DB('users_auth_scripts'); $db->setIndexBy('id'); $db->addColumn('id'); $db->addColumn('display_name'); $result = $db->select('col'); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); } else { if (!isset($result[$user->authorize])) { $message['AUTHORIZE'] = dgettext('users', 'Warning: this user\'s authorization script is broken. Choose another and update.'); } $form->addSelect('authorize', $result); $form->setMatch('authorize', $user->authorize); $form->setLabel('authorize', dgettext('users', 'Authorization')); } } if (!$user->id || $user->canChangePassword()) { $form->addText('username', $user->getUsername()); $form->setRequired('username'); $form->setLabel('username', dgettext('users', 'Username')); $form->addPassword('password1'); $form->addPassword('password2'); $form->setLabel('password1', dgettext('users', 'Password')); $form->addButton('create_pw', dgettext('users', 'Generate password')); } else { $form->addTplTag('USERNAME', $user->getUsername()); $form->addTplTag('USERNAME_LABEL', '<strong>' . dgettext('users', 'Username') . '</strong>'); } $form->addText('display_name', $user->display_name); $form->addText('email', $user->getEmail()); $form->setSize('email', 30); $form->setRequired('email'); $form->setLabel('email', dgettext('users', 'Email Address')); $form->setLabel('display_name', dgettext('users', 'Display name')); if (isset($tpl)) { $form->mergeTemplate($tpl); } $template = $form->getTemplate(); $vars['action'] = 'admin'; $vars['user_id'] = $user->id; if ($user->id) { $vars['command'] = 'setUserPermissions'; $links[] = PHPWS_Text::secureLink(\Icon::show('permission') . ' ' . dgettext('users', 'Permissions'), 'users', $vars, null, dgettext('users', 'Permissions'), 'btn btn-default'); } if (isset($links)) { $template['LINKS'] = implode(' | ', $links); } if (isset($message)) { foreach ($message as $tag => $error) { $template[strtoupper($tag) . '_ERROR'] = $error; } } if (!$user->id) { $template['JOIN_GROUPS'] = self::getJoinGroups(); } else { $group_ids = $user->getGroups(); if ($group_ids) { $db = Database::newDB(); $t1 = $db->addTable('users_groups'); $f1 = $t1->addField('name'); $c1 = $t1->getFieldConditional('id', $group_ids, 'in'); $c2 = $t1->getFieldConditional('user_id', 0); $db->stackConditionals($c1, $c2); while ($group = $db->selectColumn()) { $template['members'][] = array('NAME' => $group); } } if (!isset($template['members'])) { $template['EMPTY_GROUP'] = dgettext('user', 'User not a member of any group'); } } return PHPWS_Template::process($template, 'users', 'forms/userForm.tpl'); }