From 3ca8397103b7affedb7dc58fa3aff4ba20f397ec Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 6 Nov 2013 22:31:01 +0000 Subject: [PATCH] Add company information form And extend the information to email templates --- include/class.company.php | 77 +++++++++++++++++++ include/class.config.php | 8 ++ include/class.nav.php | 4 +- include/class.osticket.php | 7 +- include/i18n/en_US/form.yaml | 42 ++++++++++ .../templates/email/message.autoresp.yaml | 2 +- .../templates/email/ticket.autoreply.yaml | 2 +- .../templates/email/ticket.autoresp.yaml | 4 +- .../en_US/templates/email/ticket.notice.yaml | 2 +- .../en_US/templates/email/ticket.reply.yaml | 2 +- include/staff/dynamic-forms.inc.php | 40 +++++----- include/staff/header.inc.php | 5 +- include/staff/settings-pages.inc.php | 18 ++++- 13 files changed, 179 insertions(+), 34 deletions(-) create mode 100644 include/class.company.php diff --git a/include/class.company.php b/include/class.company.php new file mode 100644 index 000000000..5122239f2 --- /dev/null +++ b/include/class.company.php @@ -0,0 +1,77 @@ +<?php +/********************************************************************* + class.company.php + + Company information + + Peter Rotich <peter@osticket.com> + Jared Hancock <jared@osticket.com> + Copyright (c) 2006-2013 osTicket + http://www.osticket.com + + Released under the GNU General Public License WITHOUT ANY WARRANTY. + See LICENSE.TXT for details. + + vim: expandtab sw=4 ts=4 sts=4: +**********************************************************************/ +require_once(INCLUDE_DIR.'class.forms.php'); +require_once(INCLUDE_DIR.'class.dynamic_forms.php'); + +class Company { + var $form; + var $entry; + + function getForm() { + if (!isset($this->form)) { + // Look for the entry first + if ($this->form = DynamicFormEntry::lookup(array('object_type'=>'C'))) { + return $this->form; + } + // Make sure the form is in the database + elseif (!($this->form = DynamicForm::lookup(array('type'=>'C')))) { + $this->__loadDefaultForm(); + return $this->getForm(); + } + // Create an entry to be saved later + $this->form = $this->form->instanciate(); + $this->form->object_type = 'C'; + } + return $this->form; + } + + function getVar($name) { + if ($info = $this->getInfo()) { + $name = mb_strtolower($name); + if (isset($info[$name])) + return $info[$name]; + } + } + + function asVar() { + return $this->getVar('name'); + } + + function getInfo() { + return $this->getForm()->getClean(); + } + + /** + * Auto-installer. Necessary for 1.8 users between the RC1 release and + * the stable release who don't have the form in their database because + * it wan't in the yaml file for installation or upgrade. + */ + function __loadDefaultForm() { + require_once(INCLUDE_DIR.'class.i18n.php'); + + $i18n = new Internationalization(); + $tpl = $i18n->getTemplate('form.yaml'); + foreach ($tpl->getData() as $f) { + if ($f['type'] == 'C') { + $form = DynamicForm::create($f); + $form->save(); + break; + } + } + } +} +?> diff --git a/include/class.config.php b/include/class.config.php index e692adb2f..ed98ec0e4 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -934,6 +934,7 @@ class OsticketConfig extends Config { } function updatePagesSettings($vars, &$errors) { + global $ost; $f=array(); $f['landing_page_id'] = array('type'=>'int', 'required'=>1, 'error'=>'required'); @@ -951,9 +952,16 @@ class OsticketConfig extends Config { $errors['logo'] = 'Unable to upload logo image. '.$error; } + $company = $ost->company; + $company_form = $company->getForm(); + if (!$company_form->isValid()) + $errors += $company_form->errors(); + if(!Validator::process($f, $vars, $errors) || $errors) return false; + $company_form->save(); + if (isset($vars['delete-logo'])) foreach ($vars['delete-logo'] as $id) if (($vars['selected-logo'] != $id) diff --git a/include/class.nav.php b/include/class.nav.php index 9dc4a79f2..8cb8e5bb8 100644 --- a/include/class.nav.php +++ b/include/class.nav.php @@ -194,10 +194,10 @@ class AdminNav extends StaffNav{ $subnav[]=array('desc'=>'Information','href'=>'system.php','iconclass'=>'preferences'); break; case 'settings': - $subnav[]=array('desc'=>'System Preferences','href'=>'settings.php?t=system','iconclass'=>'preferences'); + $subnav[]=array('desc'=>'Company','href'=>'settings.php?t=pages','iconclass'=>'pages'); + $subnav[]=array('desc'=>'System','href'=>'settings.php?t=system','iconclass'=>'preferences'); $subnav[]=array('desc'=>'Tickets','href'=>'settings.php?t=tickets','iconclass'=>'ticket-settings'); $subnav[]=array('desc'=>'Emails','href'=>'settings.php?t=emails','iconclass'=>'email-settings'); - $subnav[]=array('desc'=>'Pages','href'=>'settings.php?t=pages','iconclass'=>'pages'); $subnav[]=array('desc'=>'Knowledgebase','href'=>'settings.php?t=kb','iconclass'=>'kb-settings'); $subnav[]=array('desc'=>'Autoresponder','href'=>'settings.php?t=autoresp','iconclass'=>'email-autoresponders'); $subnav[]=array('desc'=>'Alerts & Notices','href'=>'settings.php?t=alerts','iconclass'=>'alert-settings'); diff --git a/include/class.osticket.php b/include/class.osticket.php index 10f16bf95..839d36e4b 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -45,16 +45,20 @@ class osTicket { var $config; var $session; var $csrf; + var $company; function osTicket() { require_once(INCLUDE_DIR.'class.config.php'); //Config helper + require_once(INCLUDE_DIR.'class.company.php'); $this->session = osTicketSession::start(SESSION_TTL); // start DB based session $this->config = new OsticketConfig(); $this->csrf = new CSRF('__CSRFToken__'); + + $this->company = new Company(); } function isSystemOnline() { @@ -148,7 +152,8 @@ class osTicket { $replacer = new VariableReplacer(); $replacer->assign(array_merge($vars, - array('url' => $this->getConfig()->getBaseUrl()) + array('url' => $this->getConfig()->getBaseUrl(), + 'company' => $this->company) )); return $replacer->replaceVars($input); diff --git a/include/i18n/en_US/form.yaml b/include/i18n/en_US/form.yaml index 69b3ae30b..fe37e3bc7 100644 --- a/include/i18n/en_US/form.yaml +++ b/include/i18n/en_US/form.yaml @@ -103,3 +103,45 @@ private: true edit_mask: 3 sort: 3 + +- type: C # notrans + title: Company Information + instructions: Details available in email templates + deletable: false + fields: + - type: text # notrans + name: name # notrans + label: Company Name + required: true + sort: 1 + edit_mask: 3 + configuration: + size: 40 + length: 64 + + - type: text # notrans + name: website # notrans + label: Website + sort: 2 + configuration: + size: 40 + length: 64 + + - type: phone # notrans + name: phone # notrans + label: Phone Number + required: false + sort: 3 + configuration: + ext: false + + - type: memo # notrans + name: address + label: Address + required: false + sort: 4 + configuration: + rows: 2 + cols: 40 + html: false + diff --git a/include/i18n/en_US/templates/email/message.autoresp.yaml b/include/i18n/en_US/templates/email/message.autoresp.yaml index a4603bb2a..30c641de0 100644 --- a/include/i18n/en_US/templates/email/message.autoresp.yaml +++ b/include/i18n/en_US/templates/email/message.autoresp.yaml @@ -20,7 +20,7 @@ body: | <br> <br> <div style="color: rgb(127, 127, 127); "> - Your Company Name Team,<br> + Your %{company.name} Team,<br> %{signature} </div> <hr> diff --git a/include/i18n/en_US/templates/email/ticket.autoreply.yaml b/include/i18n/en_US/templates/email/ticket.autoreply.yaml index c4817b8b9..e50551566 100644 --- a/include/i18n/en_US/templates/email/ticket.autoreply.yaml +++ b/include/i18n/en_US/templates/email/ticket.autoreply.yaml @@ -37,7 +37,7 @@ body: | %{response} <br> <br> - <div style="color: rgb(127, 127, 127);">Your Company Name Team,<br> + <div style="color: rgb(127, 127, 127);">Your %{company.name} Team,<br> %{signature}</div> <hr> <div style="color: rgb(127, 127, 127); font-size: small; text-align: diff --git a/include/i18n/en_US/templates/email/ticket.autoresp.yaml b/include/i18n/en_US/templates/email/ticket.autoresp.yaml index 98e48c124..ebdfde6f1 100644 --- a/include/i18n/en_US/templates/email/ticket.autoresp.yaml +++ b/include/i18n/en_US/templates/email/ticket.autoresp.yaml @@ -43,11 +43,11 @@ body: | progress online</a>. <br> <br> - Your Company Name Team,<br> + Your %{company.name} Team,<br> %{signature} </td> <td style="vertical-align: top; padding-top: 12pt;"> - <span style="color: rgb(127, 127, 127); ">Company Name<br/> + <span style="color: rgb(127, 127, 127); ">%{company.name}<br/> %{signature}</span> <br> <br> diff --git a/include/i18n/en_US/templates/email/ticket.notice.yaml b/include/i18n/en_US/templates/email/ticket.notice.yaml index ba460d3aa..530f32a1f 100644 --- a/include/i18n/en_US/templates/email/ticket.notice.yaml +++ b/include/i18n/en_US/templates/email/ticket.notice.yaml @@ -41,7 +41,7 @@ body: | <br> <br> <div style="color: rgb(127, 127, 127);"> - Your Company Name Team,<br> + Your %{company.name} Team,<br> %{signature}</div> <hr> <div style="color: rgb(127, 127, 127); font-size: small; "><em>If you diff --git a/include/i18n/en_US/templates/email/ticket.reply.yaml b/include/i18n/en_US/templates/email/ticket.reply.yaml index d32259c8b..c576a7209 100644 --- a/include/i18n/en_US/templates/email/ticket.reply.yaml +++ b/include/i18n/en_US/templates/email/ticket.reply.yaml @@ -22,7 +22,7 @@ body: | <br> <br> <div style="color: rgb(127, 127, 127);"> - Your Company Name Team,<br> + Your %{company.name} Team,<br> %{signature} </div> <hr> diff --git a/include/staff/dynamic-forms.inc.php b/include/staff/dynamic-forms.inc.php index 2c4fa1d2c..35681f5b3 100644 --- a/include/staff/dynamic-forms.inc.php +++ b/include/staff/dynamic-forms.inc.php @@ -7,7 +7,7 @@ <?php $page = ($_GET['p'] && is_numeric($_GET['p'])) ? $_GET['p'] : 1; -$count = DynamicForm::objects()->filter(array('type__in'=>array('T','U','G')))->count(); +$count = DynamicForm::objects()->filter(array('type__in'=>array('G')))->count(); $pageNav = new Pagenate($count, $page, PAGE_LIMIT); $pageNav->setURL('forms.php'); $showing=$pageNav->showing().' forms'; @@ -21,35 +21,35 @@ $showing=$pageNav->showing().' forms'; <thead> <tr> <th width="7"> </th> - <th>Client Information Form <em>Added to all clients</em></th> + <th>Built-in Forms</th> <th>Last Updated</th> </tr> </thead> <tbody> - <?php foreach (UserForm::objects()->order_by('title') - ->limit($pageNav->getLimit()) - ->offset($pageNav->getStart()) as $form) { ?> + <?php + foreach (UserForm::objects()->order_by('title') as $form) { ?> <tr> <td/> - <td><a href="?id=<?php echo $form->get('id'); ?>"><?php echo $form->get('title'); ?></a></td> + <td><a href="?id=<?php echo $form->get('id'); ?>"> + <i class="icon-user"></i> <?php echo $form->get('title'); ?></a></td> <td><?php echo $form->get('updated'); ?></td> </tr> - <?php } ?> - </tbody> - <thead> + <?php } + foreach (TicketForm::objects()->order_by('title') as $form) { ?> <tr> - <th width="7"> </th> - <th>Common Ticket Form <em>Added to all tickets</em></th> - <th>Last Updated</th> + <td/> + <td><a href="?id=<?php echo $form->get('id'); ?>"> + <i class="icon-ticket icon"></i> + <?php echo $form->get('title'); ?></a></td> + <td><?php echo $form->get('updated'); ?></td> </tr> - </thead> - <tbody> - <?php foreach (TicketForm::objects()->order_by('title') - ->limit($pageNav->getLimit()) - ->offset($pageNav->getStart()) as $form) { ?> + <?php } + foreach (DynamicForm::objects()->filter(array('type'=>'C')) as $form) { ?> <tr> <td/> - <td><a href="?id=<?php echo $form->get('id'); ?>"><?php echo $form->get('title'); ?></a></td> + <td><a href="?id=<?php echo $form->get('id'); ?>"> + <i class="icon-building icon"></i> + <?php echo $form->get('title'); ?></a></td> <td><?php echo $form->get('updated'); ?></td> </tr> <?php } ?> @@ -59,7 +59,7 @@ $showing=$pageNav->showing().' forms'; <thead> <tr> <th width="7"> </th> - <th>Title</th> + <th>Custom Forms</th> <th>Last Updated</th> </tr> </thead> @@ -91,7 +91,7 @@ $showing=$pageNav->showing().' forms'; <a id="selectNone" href="#ckb">None</a> <a id="selectToggle" href="#ckb">Toggle</a> <?php }else{ - echo 'No extra forms defined yet — add one!'; + echo 'No extra forms defined yet — <a href="forms.php?a=add">add one!</a>'; } ?> </td> </tr> diff --git a/include/staff/header.inc.php b/include/staff/header.inc.php index d4e2ce612..0e8924ea9 100644 --- a/include/staff/header.inc.php +++ b/include/staff/header.inc.php @@ -25,7 +25,10 @@ <link rel="stylesheet" href="./css/typeahead.css" media="screen"> <link type="text/css" href="<?php echo ROOT_PATH; ?>css/ui-lightness/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" media="screen" /> - <link type="text/css" rel="stylesheet" href="../css/font-awesome.min.css"> + <link type="text/css" rel="stylesheet" href="<?php echo ROOT_PATH; ?>css/font-awesome.min.css"> + <!--[if IE 7]> + <link rel="stylesheet" href="<?php echo ROOT_PATH; ?>css/font-awesome-ie7.min.css"> + <![endif]--> <link type="text/css" rel="stylesheet" href="./css/dropdown.css"> <script type="text/javascript" src="./js/jquery.dropdown.js"></script> <?php diff --git a/include/staff/settings-pages.inc.php b/include/staff/settings-pages.inc.php index 43c8ea4fe..8a849c6d8 100644 --- a/include/staff/settings-pages.inc.php +++ b/include/staff/settings-pages.inc.php @@ -2,23 +2,33 @@ if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin() || !$config) die('Access Denied'); $pages = Page::getPages(); ?> -<h2>Site Pages</h2> +<h2>Company Profile</h2> <form action="settings.php?t=pages" method="post" id="save" enctype="multipart/form-data"> <?php csrf_token(); ?> <input type="hidden" name="t" value="pages" > <table class="form_table settings_table" width="940" border="0" cellspacing="0" cellpadding="2"> + <thead><tr> + <th colspan="2"> + <h4>Basic Information</h4> + </th> + </tr></thead> + <tbody> + <?php + $ost->company->getForm()->render(); + ?> + </tbody> <thead> <tr> <th colspan="2"> - <h4>Pages</h4> + <h4>Site Pages</h4> <em>To edit or add new pages go to <a href="pages.php">Manage > Site Pages</a></em> </th> </tr> </thead> <tbody> <tr> - <td width="220" class="required">Default Landing Page:</td> + <td width="220" class="required">Landing Page:</td> <td> <select name="landing_page_id"> <option value="">— Select Landing Page —</option> @@ -34,7 +44,7 @@ $pages = Page::getPages(); </td> </tr> <tr> - <td width="220" class="required">Default Offline Page:</td> + <td width="220" class="required">Offline Page:</td> <td> <select name="offline_page_id"> <option value="">— Select Offline Page —</option> -- GitLab