Example #1
0
<hr>
<p class="full-width">
    <span class="buttons pull-left">
        <input type="button" name="cancel" class="close"  value="<?php echo __('Cancel'); ?>">
    </span>
    <span class="buttons pull-right">
        <input type="submit" value="<?php echo __('Continue'); ?>">
    </span>
 </p>
</form>
</div>
<div id="new-org-form" style="display:<?php echo $org ? 'none' :'block'; ?>;">
<form method="post" class="org" action="<?php echo $info['action'] ?: '#orgs/add'; ?>">
    <table width="100%" class="fixed">
    <?php
        if (!$form) $form = OrganizationForm::getInstance();
        $form->render(true, __('Create New Organization')); ?>
    </table>
    <hr>
    <p class="full-width">
        <span class="buttons pull-left">
            <input type="reset" value="<?php echo __('Reset'); ?>">
            <input type="button" name="cancel" class="<?php echo $org ? 'cancel' : 'close' ?>"
                value="<?php echo __('Cancel'); ?>">
        </span>
        <span class="buttons pull-right">
            <input type="submit" value="<?php echo __('Add Organization'); ?>">
        </span>
     </p>
</form>
</div>
 function updateOrg($id, $orgId = 0)
 {
     global $thisstaff;
     if (!$thisstaff) {
         Http::response(403, 'Login Required');
     } elseif (!($user = User::lookup($id))) {
         Http::response(404, 'Unknown customer');
     }
     $info = array();
     $info['title'] = 'Organization for ' . Format::htmlchars($user->getName());
     $info['action'] = '#users/' . $user->getId() . '/org';
     $info['onselect'] = 'ajax.php/users/' . $user->getId() . '/org';
     if ($_POST) {
         if ($_POST['orgid']) {
             //Existing org.
             if (!($org = Organization::lookup($_POST['orgid']))) {
                 $info['error'] = 'Unknown organization selected';
             }
         } else {
             //Creating new org.
             $form = OrganizationForm::getDefaultForm()->getForm($_POST);
             if (!($org = Organization::fromForm($form))) {
                 $info['error'] = 'Unable to create organization - try again!';
             }
         }
         if ($org && $user->setOrganization($org)) {
             Http::response(201, $org->to_json());
         } elseif (!$info['error']) {
             $info['error'] = 'Unable to add organization - try again!';
         }
     } elseif ($orgId) {
         $org = Organization::lookup($orgId);
     } elseif ($org = $user->getOrganization()) {
         $info['title'] = sprintf('%s &mdash; %s', Format::htmlchars($user->getName()), 'Organization');
         $info['action'] = $info['onselect'] = '';
         $tmpl = 'org.tmpl.php';
     }
     if ($org && $user->getOrgId() && $org->getId() != $user->getOrgId()) {
         $info['warning'] = 'Are you sure you want to change customer\'s organization?';
     }
     $tmpl = $tmpl ?: 'org-lookup.tmpl.php';
     ob_start();
     include STAFFINC_DIR . "templates/{$tmpl}";
     $resp = ob_get_contents();
     ob_end_clean();
     return $resp;
 }
 function addOrg()
 {
     $info = array();
     if ($_POST) {
         $form = OrganizationForm::getDefaultForm()->getForm($_POST);
         if ($org = Organization::fromForm($form)) {
             Http::response(201, $org->to_json());
         }
         $info = array('error' => __('Error adding organization - try again!'));
     }
     $info['title'] = __('Add New Organization');
     $info['search'] = false;
     return self::_lookupform($form, $info);
 }
Example #4
0
 static function saveOrganizations($sql, $filename, $how = 'csv')
 {
     $exclude = array('name');
     $form = OrganizationForm::getDefaultForm();
     $fields = $form->getExportableFields($exclude);
     // Field selection callback
     $fname = function ($f) {
         return 'cdata.`' . $f->getSelectName() . '` AS __field_' . $f->get('id');
     };
     $sql = substr_replace($sql, ',' . implode(',', array_map($fname, $fields)) . ' ', strpos($sql, 'FROM '), 0);
     $sql = substr_replace($sql, 'LEFT JOIN (' . $form->getCrossTabQuery($form->type, '_org_id', $exclude) . ') cdata
                 ON (cdata._org_id = org.id) ', strpos($sql, 'WHERE '), 0);
     $cdata = array_combine(array_keys($fields), array_values(array_map(function ($f) {
         return $f->get('label');
     }, $fields)));
     $cdata += array('account_manager' => 'Account Manager', 'users' => 'Users');
     ob_start();
     echo self::dumpQuery($sql, array('name' => 'Name') + $cdata, $how, array('modify' => function (&$record, $keys) use($fields) {
         foreach ($fields as $k => $f) {
             if ($f && ($i = array_search($k, $keys)) !== false) {
                 $record[$i] = $f->export($f->to_php($record[$i]));
             }
         }
         return $record;
     }));
     $stuff = ob_get_contents();
     ob_end_clean();
     if ($stuff) {
         Http::download($filename, "text/{$how}", $stuff);
     }
     return false;
 }
 function getDynamicData()
 {
     if (!isset($this->_entries)) {
         $this->_entries = DynamicFormEntry::forOrganization($this->id)->all();
         if (!$this->_entries) {
             $g = OrganizationForm::getInstance($this->id, true);
             $g->save();
             $this->_entries[] = $g;
         }
     }
     return $this->_entries;
 }