Ejemplo n.º 1
0
 public function index()
 {
     // Cater for no module to edit.
     if (empty($this->_data['for_module'])) {
         $this->_data['for_module'] = 'shared';
     }
     $sidebarList['shared'] = array('tag' => 'Shared', 'link' => array('module' => 'dashboard', 'controller' => 'preferences', 'action' => 'index', 'for_module' => 'shared'));
     $accessObject =& AccessObject::Instance(EGS_USERNAME);
     $module = DataObjectFactory::Factory('ModuleObject');
     $modules = $module->getAll();
     $sidebar = new SidebarController($this->view);
     foreach ($modules as $module) {
         if (!class_exists(ucfirst($module) . 'Preferences')) {
             continue;
         }
         if ($accessObject->hasPermission($module, 'preferences')) {
             $sidebarList[$module] = array('tag' => ucfirst($module) . ' Preferences', 'link' => array('module' => 'dashboard', 'controller' => 'preferences', 'action' => 'index', 'for_module' => $module));
         }
     }
     if (empty($sidebarList)) {
         $flash = Flash::Instance();
         $flash->addError('There are no preferences you can edit');
         sendTo('index', 'index', array('dashboard'));
     } else {
         $sidebar->addList('Modules', $sidebarList);
     }
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $module = $this->getPreferenceClass($this->_data['for_module']);
     $this->view->set('templateCode', $module->generateTemplate());
     $this->view->set('page_title', $this->getPageName($this->_data['for_module'], 'Preferences for'));
 }
Ejemplo n.º 2
0
 public static function Factory($default_page = null, $requireLogin = true)
 {
     $prefs = UserPreferences::Instance(EGS_USERNAME);
     $default_page = $prefs->getPreferenceValue('default_page', 'shared');
     if ($default_page == null) {
         $ao = AccessObject::Instance();
         $default_page = 'module,' . $ao->getDefaultModule();
     }
     if (get_config('SETUP')) {
         if (defined('MODULE')) {
             $default_page = MODULE;
         }
     }
     $router = RouteParser::Instance();
     $modules = array();
     if (!$requireLogin || isLoggedIn()) {
         foreach ($router->getDispatch() as $key => $dispatch) {
             if (($key == 'group' || $key == 'module' || strstr($key, 'submodule')) && !empty($dispatch)) {
                 $modules[$key] = $dispatch;
             }
         }
         if (empty($modules)) {
             // Default page contains permission type and permission name
             // i.e. type is group or module
             $array = explode(',', $default_page);
             $modules[$array[0]] = $array[1];
         }
     } else {
         $modules['module'] = 'login';
     }
     $al =& AutoLoader::Instance();
     return $modules;
 }
Ejemplo n.º 3
0
function smarty_block_form($params, $content, &$smarty, $repeat)
{
    if (!empty($content)) {
        // set default output vars
        $data = array('search_id' => FALSE, 'submit_token_id' => FALSE, 'class' => '', 'content' => $content, 'method' => 'post');
        $modules = $smarty->getTemplateVars('modules');
        if (!empty($modules)) {
            $module = '';
            $prefix = 'module=';
            foreach ($modules as $mod) {
                $module .= $prefix . $mod . '&';
                $prefix = 'sub' . $prefix;
            }
        }
        if (isset($params['target'])) {
            $data['action'] = $params['target'];
        } else {
            $access = AccessObject::Instance();
            $pid = $access->getPermission($modules, $params['controller'], $params['action']);
            $data['action'] = '/?pid=' . $pid . '&' . $module . 'controller=' . $params['controller'] . '&action=' . $params['action'];
        }
        if (isset($params['subfunction'])) {
            $data['action'] .= '&subfunction=' . $params['subfunction'];
            if (isset($params['subfunctionaction'])) {
                $data['action'] .= '&subfunctionaction=' . $params['subfunctionaction'];
            }
        }
        if (isset($params['id'])) {
            $data['action'] .= '&id=' . $params['id'];
        }
        foreach ($params as $name => $value) {
            if ($name[0] === '_') {
                $data['action'] .= '&' . substr($name, 1) . '=' . $value;
            }
        }
        if (isset($params['additional_data'])) {
            foreach ($params['additional_data'] as $name => $value) {
                $data['action'] .= '&' . $name . '=' . $value;
            }
        }
        if (isset($params['class'])) {
            $data['class'] = $params['class'];
        }
        $data['original_action'] = $smarty->getTemplateVars('action');
        if (isset($_GET['search_id'])) {
            $data['search_id'] = $_GET['search_id'];
        }
        // there are some instances where we don't want the submit token
        if (strtoupper($params['submit_token']) !== 'FALSE') {
            $data['submit_token_id'] = uniqid();
            $_SESSION['submit_token'][$data['submit_token_id']] = TRUE;
        }
        $data['display_tags'] = !isset($params['notags']);
        if (isset($params['form_id'])) {
            $data['form_id'] = $params['form_id'];
        }
        // fetch smarty plugin template
        return smarty_plugin_template($smarty, $data, 'block.form');
    }
}
 public function __construct()
 {
     // CORS headers to allow certain methods
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
     header('Content-type:application/json;charset=utf-8');
     parent::__construct();
 }
Ejemplo n.º 5
0
function smarty_function_link_current($params, &$smarty)
{
    $array = $smarty->getTemplateVars('self');
    if (is_array($smarty->getTemplateVars('paging_link'))) {
        $array = $smarty->getTemplateVars('paging_link');
    }
    if (isset($array['page'])) {
        unset($array['page']);
    }
    if (isset($array['value'])) {
        unset($array['value']);
    }
    $pid = '';
    $modules = '';
    $controller = '';
    $action = '';
    if (!empty($array['module'])) {
        $modules = $array['module'];
        $module = 'module=' . $modules . '&';
        unset($array['module']);
    }
    if (!empty($array['modules'])) {
        $modules = $array['modules'];
        $module = '';
        $prefix = 'module=';
        foreach ($modules as $mod) {
            $module .= $prefix . $mod . '&';
            $prefix = 'sub' . $prefix;
        }
        unset($array['modules']);
    }
    if (!empty($array['controller'])) {
        $controller = $array['controller'];
        unset($array['controller']);
    }
    if (!empty($array['action'])) {
        $action = $array['action'];
        unset($array['action']);
    }
    if (!empty($array['pid'])) {
        $pid = $array['pid'];
        unset($array['pid']);
    } else {
        $access = AccessObject::Instance();
        $pid = $access->getPermission($modules, $controller, $action);
    }
    $action = '/?pid=' . $pid . '&' . $module . 'controller=' . $controller . '&action=' . $action;
    foreach ($array as $name => $value) {
        $action .= '&' . $name . '=' . $value;
    }
    $content = '<input type="hidden" id="paging_url" name="paging_url" value="' . $action . '">';
    if (isset($_GET['search_id']) && !isset($array['search_id'])) {
        $content .= '<input type="hidden" name="search_id" value="' . $_GET['search_id'] . '" />';
    }
    $page_num = $params['page'];
    $content .= '<input type="text" name="goto_page" value="' . $page_num . '" class="paging">';
    return $content;
}
Ejemplo n.º 6
0
 public function __construct()
 {
     // CORS headers to allow certain methods
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: POST');
     header('Content-type:application/json;charset=utf-8');
     header('X-Content-Type-Options: nosniff');
     parent::__construct();
 }
Ejemplo n.º 7
0
 function __construct($getCurrentValues = true, $model = 'UserPreferences', $username = EGS_USERNAME)
 {
     parent::__construct();
     $userPreferences = $model::instance($username);
     $this->setModuleName('shared');
     // items-per-page
     if ($getCurrentValues) {
         $num_items = $userPreferences->getPreferenceValue('items-per-page', 'shared');
     } else {
         $num_items = 10;
     }
     $this->registerPreference(array('name' => 'items-per-page', 'display_name' => 'Items to display per page', 'type' => 'select', 'value' => $num_items, 'data' => array(array('label' => 5, 'value' => 5), array('label' => 10, 'value' => 10), array('label' => 15, 'value' => 15), array('label' => 20, 'value' => 20), array('label' => 25, 'value' => 25), array('label' => 30, 'value' => 30), array('label' => 35, 'value' => 35), array('label' => 40, 'value' => 40), array('label' => 45, 'value' => 45), array('label' => 50, 'value' => 50)), 'default' => '10', 'position' => 1));
     // default_printer
     $printerlist = array();
     foreach (printController::selectPrinters() as $key => $printer) {
         $printerlist[] = array('label' => $printer, 'value' => $key);
     }
     if ($getCurrentValues) {
         $current_printer = $userPreferences->getPreferenceValue('default_printer', 'shared');
     } else {
         $current_printer = '';
     }
     $this->registerPreference(array('name' => 'default_printer', 'display_name' => 'Default Printer', 'type' => 'select', 'value' => $current_printer, 'data' => $printerlist, 'default' => '', 'position' => 2));
     // password change
     if ($username == EGS_USERNAME) {
         $this->registerField(array('name' => 'current_password', 'display_name' => 'Current Password', 'type' => 'password', 'value' => '', 'position' => 3));
         $this->registerHandledPreference(array('name' => 'new_password', 'display_name' => 'New Password', 'type' => 'password', 'value' => '', 'position' => 4, 'callback' => 'changePassword'));
         $this->registerField(array('name' => 'confirm_password', 'display_name' => 'Confirm Password', 'type' => 'password', 'value' => '', 'position' => 5));
     }
     // pdf-preview/pdf-browser-printing
     if ($getCurrentValues) {
         $pdf_preview = $userPreferences->getPreferenceValue('pdf-preview', 'shared');
         $pdf_browser_printing = $userPreferences->getPreferenceValue('pdf-browser-printing', 'shared');
     } else {
         $pdf_preview = 'off';
         $pdf_browser_printing = 'off';
     }
     $this->registerPreference(array('name' => 'pdf-preview', 'display_name' => 'Enable PDF Preview', 'type' => 'checkbox', 'status' => empty($pdf_preview) || $pdf_preview == 'off' ? 'off' : 'on', 'default' => 'off', 'position' => 6));
     $this->registerPreference(array('name' => 'pdf-browser-printing', 'display_name' => 'Enable browser PDF printing', 'type' => 'checkbox', 'status' => empty($pdf_browser_printing) || $pdf_browser_printing == 'off' ? 'off' : 'on', 'default' => 'off', 'position' => 7));
     // default_page
     $modulelist = array();
     // Get modules user has access to
     $ao = AccessObject::instance();
     $per = DataObjectFactory::Factory('Permission');
     $permissions = $ao->getUserModules($username);
     if (!empty($permissions)) {
         foreach ($permissions as $permission) {
             $modulelist[] = array('label' => $permission['title'], 'value' => strtolower($per->getEnum('type', $permission['type'])) . ',' . $permission['permission']);
         }
     }
     if ($getCurrentValues) {
         $default_page = $userPreferences->getPreferenceValue('default_page', 'shared');
     } else {
         $default_page = '';
     }
     $this->registerPreference(array('name' => 'default_page', 'display_name' => 'Home page', 'type' => 'select', 'value' => $default_page, 'data' => $modulelist, 'default' => '', 'position' => 8));
 }
Ejemplo n.º 8
0
 public function getByRoles($_permissions_id = '')
 {
     $this->idField = 'report_id';
     $this->identifierField = 'description';
     $cc = new ConstraintChain();
     if (!empty($_permissions_id)) {
         $cc->add(new Constraint('permissions_id', '=', $_permissions_id));
     }
     $ao = AccessObject::Instance();
     $cc->add(new Constraint('role_id', 'in', '(' . implode(',', $ao->roles) . ')'));
     return $this->getAll($cc, true, true);
 }
Ejemplo n.º 9
0
 function setMenuData($module, $pid)
 {
     $ao = AccessObject::instance();
     if (empty($pid)) {
         $pid = $ao->getPermission($module);
     }
     if (!empty($pid)) {
         $this->contents = $this->getMenuLinks($ao->tree, $pid);
     } else {
         $this->contents = array();
     }
 }
Ejemplo n.º 10
0
 function populate()
 {
     $module = DataObjectFactory::Factory('ModuleObject');
     $module->loadBy('name', $_GET['module']);
     $files = new EntityAttachmentCollection();
     $files->setParams();
     $pl = new PageList(' Documents');
     $sh = new SearchHandler($files, FALSE);
     $fields = array('id', 'file as document', 'revision', 'note', 'file_id');
     $sh->setOrderBy('file');
     $sh->setFields($fields);
     $sh->addConstraint(new Constraint('entity_id', '=', $module->id));
     $sh->addConstraint(new Constraint('data_model', '=', 'moduleobject'));
     $this->setSearchLimit($sh);
     $files->load($sh);
     $this->contents = $files;
     $ao = AccessObject::Instance();
     $this->contents->can_upload = $ao->hasPermission($_GET['module'], 'attachments', 'new');
 }
Ejemplo n.º 11
0
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $ticket = $this->_uses[$this->modeltype];
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Actions', array('all' => array('tag' => 'View All Tickets', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'index'))));
     $sidebar->addList('currently_viewing', array($ticket->summary => array('tag' => $ticket->summary, 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view', 'id' => $ticket->id)), 'edit' => array('tag' => 'Edit', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'edit', 'id' => $ticket->id)), 'add_response' => array('tag' => 'Add Response', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'add_response', 'id' => $ticket->id)), 'extract_change_log' => array('tag' => 'extract_change_log', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'extract_change_log', 'id' => $ticket->id))));
     $sidebar->addList('related_items', array('attachments' => array('tag' => 'Attachments', 'link' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'new', 'ticket_id' => $ticket->id)), 'hours' => array('tag' => 'Hours', 'link' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'new', 'ticket_id' => $ticket->id)), 'components' => array('tag' => 'Components Affected', 'link' => array('module' => 'ticketing', 'controller' => 'ticketmoduleversions', 'action' => 'viewticket', 'ticket_id' => $ticket->id))));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $responses = new TicketResponseCollection(new TicketResponse());
     $sh = new SearchHandler($responses, false);
     $sh->AddConstraint(new Constraint('ticket_id', '=', $ticket->id));
     $sh->setOrderBy('created', 'asc');
     $responses->load($sh);
     $pageResponses = array();
     foreach ($responses->getContents() as $response) {
         if ($response->internal === 't') {
             $response->type = 'internal';
         }
         $pageResponses[] = $response;
     }
     $this->view->set('responses', $pageResponses);
     $ao = AccessObject::Instance();
     $this->view->set('ticketing_client', false);
     if ($ao->hasPermission('ticketing_client')) {
         $this->view->set('ticketing_client', true);
     }
     $db = DB::Instance();
     $query = 'SELECT ceil((EXTRACT(hour FROM SUM(duration)) + (EXTRACT(minute FROM SUM (duration))/60))*4)/4 AS duration FROM hours WHERE ticket_id = ' . $db->qstr($ticket->id);
     $duration = $db->GetOne($query);
     if ($duration === null) {
         $this->view->set('duration', 0 . ' hours');
     } else {
         $this->view->set('duration', $duration . ' hours');
     }
 }
Ejemplo n.º 12
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     $modelname = get_class($this->_templateobject);
     if (!$this->checkParams($modelname)) {
         sendBack();
     }
     $company = $this->_templateobject;
     $companydata = $this->_data[$modelname];
     $companyidfield = $company->idField;
     $companyid = '';
     if (isset($companydata[$companyidfield]) && !empty($companydata[$companyidfield])) {
         $companyid = $companydata[$companyidfield];
         $company->load($companyid);
         if ($company === false) {
             $flash->addError('Could not load Company for id=' . $companyid . ' - Abandoned');
             sendBack();
         }
     }
     $db =& DB::Instance();
     $db->StartTrans();
     $partycontactmethod = DataObjectFactory::Factory('PartyContactMethod');
     foreach ($partycontactmethod->getEnumOptions('type') as $key => $type) {
         if (isset($this->_data[$type]['PartyContactMethod']) && isset($this->_data[$type]['Contactmethod']) && empty($this->_data[$type]['Contactmethod']['contact'])) {
             if (!empty($this->_data[$type]['PartyContactMethod'][$partycontactmethod->idField])) {
                 $partycontactmethod->delete($this->_data[$type]['PartyContactMethod'][$partycontactmethod->idField], $errors);
             }
             unset($this->_data[$type]);
         }
     }
     if (count($errors) == 0 && parent::save($modelname, $this->_data, $errors)) {
         foreach ($this->saved_models as $model) {
             if (isset($model[$modelname])) {
                 $company = $model[$modelname];
                 break;
             }
         }
         $this->company_id = $company->{$companyidfield};
         if (isset($companydata['crm'])) {
             $crm_data = $companydata['crm'];
             $ao =& AccessObject::Instance(EGS_USERNAME);
             if ($ao->hasPermission('crm')) {
                 $crm_data['company_id'] = $company->{$companyidfield};
                 parent::save('CompanyCrm', $crm_data);
             }
         }
         $company_category = DataObjectFactory::Factory('CompanyInCategories');
         $current_categories = $company_category->getCategoryID($company->{$companyidfield});
         $check_categories = array();
         $delete_categories = array();
         $insert_categories = array();
         $new_categories = array();
         if (isset($this->_data['ContactCategories'])) {
             $delete_categories = array_diff($current_categories, $this->_data['ContactCategories']['category_id']);
             $insert_categories = array_diff($this->_data['ContactCategories']['category_id'], $current_categories);
             $new_categories = array_diff($current_categories, $delete_categories);
             $new_categories += $insert_categories;
         } else {
             $delete_categories = $current_categories;
         }
         $ledger_category = DataObjectFactory::Factory('LedgerCategory');
         $ledger_types = $ledger_category->checkCompanyUsage($company->{$companyidfield});
         foreach ($ledger_types as $ledger_type => $categories) {
             if ($categories['exists'] && !array_intersect($categories['categories'], $new_categories)) {
                 foreach (array_intersect($categories['categories'], $delete_categories) as $category_id) {
                     $category = DataObjectFactory::Factory('ContactCategory');
                     $category->load($category_id);
                     $errors[$category->name] = 'Cannot remove category ' . $category->name . ' - ' . $ledger_type . ' entry exists';
                 }
             }
         }
         $result = count($errors) == 0;
         if (!empty($delete_categories) && $result) {
             // All OK, so delete the associations
             $result = $company_category->delete(array_keys($delete_categories), $errors);
         }
         if (!empty($insert_categories) && $result) {
             // No errors and some new categories to assign to the company
             $result = $company_category->insert($insert_categories, $company->{$companyidfield});
         }
         if ($result) {
             // All OK
             $db->CompleteTrans();
             sendTo($this->name, 'view', $this->_modules, array($companyidfield => $company->{$companyidfield}));
         }
     }
     // Errors
     $flash->addErrors($errors);
     $db->FailTrans();
     $db->CompleteTrans();
     $this->refresh();
 }
Ejemplo n.º 13
0
 public function view()
 {
     $ticket = $this->_uses['Ticket'];
     $ticket->load($this->_data['id']) or sendBack();
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('currently_viewing', array($ticket->summary => array('tag' => $ticket->summary, 'link' => array('module' => 'ticketing', 'controller' => 'client', 'action' => 'view', 'id' => $ticket->id)), 'edit' => array('tag' => 'Edit', 'link' => array('module' => 'ticketing', 'controller' => 'client', 'action' => 'edit', 'id' => $ticket->id)), 'add_response' => array('tag' => 'Add Response', 'link' => array('module' => 'ticketing', 'controller' => 'client', 'action' => 'add_response', 'id' => $ticket->id))));
     $rel_items = array();
     $ao = AccessObject::Instance();
     if ($ao->hasPermission('ticketing', 'attachments')) {
         $rel_items += array('attachments' => array('tag' => 'Attachments', 'link' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'new', 'ticket_id' => $ticket->id)));
     }
     if ($ao->hasPermission('ticketing', 'hours')) {
         $rel_items += array('hours' => array('tag' => 'Hours', 'link' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'new', 'ticket_id' => $ticket->id)));
     }
     if (count($rel_items) > 0) {
         $sidebar->addList('related_items', $rel_items);
     }
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $responses = new TicketResponseCollection(new TicketResponse());
     $sh = new SearchHandler($responses, false);
     $sh->AddConstraint(new Constraint('ticket_id', '=', $ticket->id));
     $sh->AddConstraint(new Constraint('internal', '=', 'f'));
     $responses->load($sh);
     $this->view->set('responses', $responses->getContents());
 }
Ejemplo n.º 14
0
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $person = $this->_uses[$this->modeltype];
     $person_id = $person->{$person->idField};
     $party_id = $person->party_id;
     $company = DataObjectFactory::Factory('Company');
     $slcustomer = DataObjectFactory::Factory('SLCustomer');
     if ($person->isLoaded()) {
         $company->load($person->company_id);
         $slcustomer->loadBy('company_id', $person->company_id);
     }
     if (!$person->isLoaded()) {
         $flash = Flash::instance();
         $flash->addError('You do not have permission to view this person.');
         sendTo($this->name, 'index', $this->_modules);
         return;
     }
     $sidebar = new SidebarController($this->view);
     // Need loose coupling method - use person categories?
     $employee = DataObjectFactory::Factory('Employee');
     $employee->loadBy('person_id', $person_id);
     if ($employee->isLoaded()) {
         $sidebar->addList('currently_viewing', array('view' => array('tag' => 'view ' . $person->fullname, 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view', 'id' => $person_id))));
     } else {
         $sidebar->addCurrentBox('currently_viewing', $person->fullname, array('module' => 'contacts', 'controller' => 'persons', 'id' => $person->id));
     }
     $items = array();
     $ao = AccessObject::Instance();
     if ($ao->hasPermission('crm')) {
         $items += array('opportunities' => array('tag' => 'Opportunities', 'link' => array('module' => 'crm', 'controller' => 'opportunitys', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'crm', 'controller' => 'opportunitys', 'action' => 'new', 'person_id' => $person_id)), 'activities' => array('tag' => 'Activities', 'link' => array('module' => 'crm', 'controller' => 'activitys', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'crm', 'controller' => 'activitys', 'action' => 'new', 'person_id' => $person_id)));
     }
     if ($ao->hasPermission('ticketing')) {
         $items += array('tickets' => array('tag' => 'Tickets', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'viewcompany', 'originator_person_id' => $person_id), 'new' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'new', 'originator_person_id' => $person_id)));
     }
     if (isModuleAdmin('projects')) {
         $items += array('resource_template' => array('tag' => 'Resource Template', 'link' => array('module' => 'projects', 'controller' => 'resourcetemplate', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'projects', 'controller' => 'resourcetemplate', 'action' => 'new', 'person_id' => $person_id)));
     }
     $items += array('spacer', 'notes' => array('tag' => 'Notes', 'link' => array('module' => 'contacts', 'controller' => 'partynotes', 'action' => 'viewperson', 'party_id' => $party_id), 'new' => array('module' => 'contacts', 'controller' => 'partynotes', 'action' => 'new', 'party_id' => $party_id)), 'spacer', 'attachments' => array('tag' => 'Attachments', 'link' => array('module' => 'contacts', 'controller' => 'personattachments', 'action' => 'index', 'person_id' => $person_id), 'new' => array('module' => 'contacts', 'controller' => 'personattachments', 'action' => 'new', 'data_model' => 'person', 'entity_id' => $person_id)), 'spacer', 'addresses' => array('tag' => 'Addresses', 'link' => array('module' => 'contacts', 'controller' => 'partyaddresss', 'action' => 'viewperson', 'party_id' => $party_id), 'new' => array('module' => 'contacts', 'controller' => 'partyaddresss', 'action' => 'new', 'party_id' => $party_id)), 'spacer', 'phone' => array('tag' => 'Phone', 'link' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'viewperson', 'party_id' => $party_id, 'type' => 'T'), 'new' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'new', 'party_id' => $party_id, 'type' => 'T')), 'mobile' => array('tag' => 'Mobile', 'link' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'viewperson', 'party_id' => $party_id, 'type' => 'M'), 'new' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'new', 'party_id' => $party_id, 'type' => 'M')), 'fax' => array('tag' => 'Fax', 'link' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'viewperson', 'party_id' => $party_id, 'type' => 'F'), 'new' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'new', 'party_id' => $party_id, 'type' => 'F')), 'email' => array('tag' => 'Email', 'link' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'viewperson', 'party_id' => $party_id, 'type' => 'E'), 'new' => array('module' => 'contacts', 'controller' => 'partycontactmethods', 'action' => 'new', 'party_id' => $party_id, 'type' => 'E')), 'spacer', 'meetings' => array('tag' => 'Meetings', 'link' => array('module' => 'calendar', 'controller' => 'calendarevents', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'calendar', 'controller' => 'calendarevents', 'action' => 'new', 'person_id' => $person_id)), 'calls' => array('tag' => 'Calls', 'link' => array('module' => 'contacts', 'controller' => 'loggedcalls', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'contacts', 'controller' => 'loggedcalls', 'action' => 'new', 'person_id' => $person_id)));
     if ($slcustomer->isLoaded()) {
         $items += array('sorders' => array('tag' => 'Sales Orders/Quotes', 'link' => array('module' => 'sales_order', 'controller' => 'sorders', 'action' => 'viewperson', 'person_id' => $person_id), 'new' => array('module' => 'sales_order', 'controller' => 'sorders', 'action' => 'new', 'person_id' => $person_id, 'slmaster_id' => $slcustomer->id)));
     }
     $sidebar->addList('related_items', $items);
     $category = DataObjectFactory::Factory('peopleInCategories');
     $this->view->set('categories', implode(',', $category->getCategorynames($person_id)));
     $current_categories = $category->getCategoryID($person_id);
     $ledger_category = DataObjectFactory::Factory('LedgerCategory');
     foreach ($ledger_category->getPersonTypes($current_categories) as $model_name => $model_detail) {
         $do = DataObjectFactory::Factory($model_name);
         $do->loadBy('person_id', $person_id);
         if ($do->isLoaded()) {
             $sidebar->addList('related_items', array($model_name => array('tag' => $do->getTitle(), 'link' => array('module' => $model_detail['module'], 'controller' => $model_detail['controller'], 'action' => 'view', $do->idField => $do->{$do->idField}))));
         } else {
             $sidebar->addList('related_items', array($model_name => array('tag' => $do->getTitle(), 'new' => array('module' => $model_detail['module'], 'controller' => $model_detail['controller'], 'action' => 'new', 'person_id' => $person->{$person->idField}))));
         }
     }
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $category = DataObjectFactory::Factory('PeopleInCategories');
     $this->view->set('categories', implode(',', $category->getCategorynames($person_id)));
     if ($person instanceof Person) {
         $pl = new PreferencePageList('recently_viewed_people' . EGS_COMPANY_ID);
         $pl->addPage(new Page(array('module' => 'contacts', 'controller' => 'persons', 'action' => 'view', 'id' => $person_id), 'person', $person->firstname . ' ' . $person->surname));
         $pl->save();
     }
 }
Ejemplo n.º 15
0
 public function display()
 {
     $start = gettimeofday(TRUE);
     // ATTN: check system always returns true?
     if (!$this->check_system()) {
         $this->login_required = FALSE;
         // if (!defined('SETUP'))
         // {
         // define('SETUP', TRUE);
         // }
         if (!defined('MODULE')) {
             define('MODULE', 'system_admin');
         }
         if (!defined('CONTROLLER')) {
             define('CONTROLLER', 'SystemsController');
         }
     }
     $this->load_essential();
     debug('system::display session data:' . print_r($_SESSION, TRUE));
     $this->user = FALSE;
     if (isLoggedIn()) {
         // Sets the global constants EGS_USERNAME and EGS_COMPANY_ID
         setupLoggedInUser();
         $this->user = getCurrentUser();
         $this->access = AccessObject::Instance($_SESSION['username']);
     } else {
         define('EGS_COMPANY_ID', -1);
         define('EGS_USERNAME', $_SESSION['username']);
         $this->access = AccessObject::Instance();
     }
     $this->setView();
     $this->view->set("accessTree", $this->access->tree);
     $this->view->set('access', $this->access);
     $this->setController();
     $this->setTemplates();
     $this->setAction();
     $csrf = new \Riimu\Kit\CSRF\CSRFHandler();
     // check that the csrf token is valid
     if (!$this->csrfValid()) {
         sendBack();
     }
     $csrf_token = $csrf->getToken();
     // make csrf token available to smarty templates
     $this->view->set('csrf_token', $csrf_token);
     if (isLoggedIn()) {
         $this->checkPermission();
     }
     // output standard arrays to smarty
     $this->view->set("module_css", $this->get_css());
     $this->view->set("module_js", $this->get_js());
     $this->view->set('current_user', $this->user);
     $action = $this->action;
     $controller = $this->controller;
     $theme = '';
     if (defined('EGS_COMPANY_ID') && EGS_COMPANY_ID !== 'null' && EGS_COMPANY_ID > 0) {
         $sc = DataObjectFactory::Factory('Systemcompany');
         $sc->load(EGS_COMPANY_ID);
         if ($sc->isLoaded()) {
             define('SYSTEM_COMPANY', $sc->company);
             define('COMPANY_ID', $sc->company_id);
             $theme = $sc->theme;
             $this->available = $sc->access_enabled == 'NONE' ? FALSE : TRUE;
             $this->audit = $sc->audit_enabled == 't' ? TRUE : FALSE;
             $this->debug = $sc->debug_enabled == 't' ? TRUE : FALSE;
             $this->view->set('info_message', $sc->info_message);
             $this->view->set('systemcompany', $sc);
         }
     }
     $policy = DataObjectFactory::Factory('SystemObjectPolicy');
     if ($policy->getCount() > 0) {
         define('SYSTEM_POLICIES_ENABLED', TRUE);
     } else {
         define('SYSTEM_POLICIES_ENABLED', FALSE);
     }
     if (!defined('SYSTEM_COMPANY')) {
         define('SYSTEM_COMPANY', '');
     }
     if (!defined('COMPANY_ID')) {
         define('COMPANY_ID', '');
     }
     // Set auditing/debugging for logged in user
     if ($this->user) {
         $this->audit = $this->audit ? $this->audit : ($this->user->audit_enabled == 't' ? TRUE : FALSE);
         $this->debug = $this->debug ? $this->debug : ($this->user->debug_enabled == 't' ? TRUE : FALSE);
         $this->available = $this->available ? $this->user->access_enabled == 't' ? TRUE : FALSE : $this->available;
     }
     if (!$this->available && isLoggedIn()) {
         $_SESSION['loggedin'] = FALSE;
         $_SESSION['username'] = null;
         $flash = Flash::Instance();
         $flash->addError('The system is unavailable at present');
         $flash->save();
         sendto('');
     }
     define('AUDIT', $this->audit);
     define('DEBUG', $this->debug);
     $db = DB::Instance();
     $db->debug(DEBUG);
     if (defined('LOGIN_PAGE_THEME') && $this->modules['module'] == 'login') {
         $theme = LOGIN_PAGE_THEME;
     }
     if (!empty($theme)) {
         define('THEME', $theme);
     } else {
         define('THEME', 'default');
     }
     $this->view->set('theme', THEME);
     if (!defined('EGS_CURRENCY')) {
         define('EGS_CURRENCY', 'GBP');
     }
     if (class_exists('Currency')) {
         $currency = DataObjectFactory::Factory('Currency');
         $currency->loadBy('currency', EGS_CURRENCY);
         if ($currency) {
             define('EGS_CURRENCY_SYMBOL', utf8_decode($currency->symbol));
         }
     }
     if (!defined('EGS_CURRENCY_SYMBOL')) {
         define('EGS_CURRENCY_SYMBOL', utf8_decode('£'));
     }
     /**
      * *BEGIN CACHE CHECK*****
      */
     if (!defined('EGS_COMPANY_ID')) {
         define('EGS_COMPANY_ID', '');
     }
     if (DEBUG) {
         $this->writeDebug();
     }
     $cache_key = md5($_SERVER['REQUEST_URI'] . EGS_COMPANY_ID . EGS_USERNAME);
     if (TRUE || !$smarty->isCached('index.tpl', $cache_key)) {
         $flash = Flash::Instance();
         $config = Config::Instance();
         // output all the variables to smarty
         // this replaces $smarty.const.setting_name
         $this->view->assign('config', $config->get_all());
         setRefererPage();
         debug('system::display Calling function ' . get_class($controller) . '::' . $action);
         // echo 'system::display (1),'.microtime(TRUE).'<br>';
         $controller->checkRequest($this->request, $action)->{$action}();
         // echo 'system::display (2),'.microtime(TRUE).'<br>';
         $flash->save();
         // Save any flash messages for audit purposes
         $this->flash['errors'] = $flash->getMessages('errors');
         $this->flash['warnings'] = $flash->getMessages('warnings');
         $this->flash['messages'] = $flash->getMessages('messages');
         if (isLoggedIn()) {
             $this->access->save();
         }
         // assign stuff to smarty
         $controller->assignModels();
         // this code fires $controller->index() if (perhaps) getPrintActions doesn't exist,
         // thus overwriting the sidebar. Only fire if subclass of printController
         if (is_subclass_of($controller, 'printController') && $action != 'printDialog') {
             $this->view->assign('printaction', $controller->getPrintActions());
         }
         $controllername = str_replace('Controller', '', get_class($controller));
         $this->pid = $this->access->getPermission($this->modules, $controllername, $action);
         $self = array();
         if (!empty($this->pid)) {
             $self['pid'] = $this->pid;
         }
         $self['modules'] = $this->modules;
         // $self['controller']=$controllername;
         // $self['action']=$action;
         $qstring = $_GET;
         foreach ($qstring as $qname => $qvalue) {
             if (!in_array($qname, array('orderby', 'page'))) {
                 $self[$qname] = $qvalue;
             }
         }
         $this->view->assign('self', $self);
         if (isset($this->user)) {
             $this->view->assign('current_user', $this->user);
         }
         // Session timed out on input form so save the form data while the user logs back in
         // See system::setController for where the form data is read after logging back in
         if ($this->modules['module'] == 'login' && !empty($_POST)) {
             $_SESSION['data'] = $_POST;
         }
         $echo = $controller->view->get('echo');
         if (($this->ajax || $this->json) && $echo !== FALSE) {
             echo $controller->view->get('echo');
             exit;
         } elseif ($this->modules['module'] == 'login') {
             $current = getParamsArray($_SERVER['QUERY_STRING']);
             $referer['modules'] = $current['modules'];
             $referer['controller'] = 'Index';
             $referer['action'] = 'index';
             unset($referer['other']);
             $_SESSION['referer'][setParamsString($current)] = setParamsString($referer);
         } elseif (!isset($_GET['ajax'])) {
             $referer = '';
             if (!empty($_POST)) {
                 // This is a save form so set the referer to be the referer's referer!
                 $referer = isset($_SESSION['refererPage']) ? $_SESSION['refererPage'] : '';
             }
             setReferer($referer);
             $current = getParamsArray($_SERVER['QUERY_STRING']);
             $flash = Flash::Instance();
             $current += array('messages' => $flash->getMessages('messages'), 'warnings' => $flash->getMessages('warnings'), 'errors' => $flash->getMessages('errors'));
             $_SESSION['submit_token']['current'] = $current;
         }
     }
     showtime('pre-display');
     // echo 'System::display end '.(gettimeofday(TRUE)-$start).'<br>';
     // echo 'system::display (3),'.microtime(TRUE).'<br>';
     $this->view->display('index_page.tpl', $cache_key);
     // echo 'system::display (4),'.microtime(TRUE).'<br>';
     showtime('post-display');
 }
Ejemplo n.º 16
0
 public function getEvents()
 {
     $despatch_events = new SODespatchEventCollection();
     $sh = new SearchHandler($despatch_events, false);
     $sh->addConstraint(new Constraint('end_time', '>=', date('Y-m-d H:i:s', $this->_data['start'])));
     $sh->addConstraint(new Constraint('start_time', '<', date('Y-m-d H:i:s', $this->_data['end'])));
     $sh->addConstraint(new Constraint('status', 'NOT IN', "('X')"));
     $despatch_events->load($sh);
     $events = array();
     $output_events = array();
     $events = $despatch_events->getArray();
     $colours = array('tc' => 'fc_red', 'tnc' => 'fc_green', 'nbi' => 'fc_pink', 'led' => 'fc_yellow');
     $accessobject = AccessObject::Instance();
     $editable = $accessobject->hasPermission('despatch', 'sodespatchevents', 'edit');
     // pardon my ignorance, but we shouldn't have to check is an array is empty... right?
     if (!empty($events)) {
         foreach ($events as $key => $value) {
             $output_events[] = array('id' => $value['id'], 'title' => $value['title'], 'allDay' => false, 'start' => strtotime($value['start_time']), 'end' => strtotime($value['end_time']), 'className' => $colours[strtolower($value['status'])], 'editable' => $editable);
         }
     }
     echo json_encode($output_events);
     exit;
 }
Ejemplo n.º 17
0
 public function getHolidays()
 {
     $holidays = new HolidayRequestCollection();
     $s_data = array();
     $this->setSearch('holidaySearch', 'useDefault', $s_data);
     $sh = $this->setSearchHandler($holidays);
     $sh->addConstraint(new Constraint('end_date', '>=', date('Y-m-d H:i:s', $this->_data['start'])));
     $sh->addConstraint(new Constraint('start_date', '<', date('Y-m-d H:i:s', $this->_data['end'])));
     $sh->addConstraint($this->search->toConstraintChain());
     $fields = $sh->fields;
     $fields[] = 'reason_declined';
     $fields[] = 'all_day';
     $sh->setFields($fields);
     $holidayrequests = $holidays->load($sh, '', RETURN_ROWS);
     $output_events = array();
     $colours = array('A' => 'fc_green', 'C' => 'fc_grey', 'D' => 'fc_red', 'W' => 'fc_yellow');
     $accessobject = AccessObject::Instance();
     $access_allowed = $accessobject->hasPermission('hr', 'holidayrequests', 'edit');
     $current_employee = $this->get_employee_id();
     foreach ($holidayrequests as $key => $value) {
         //			$self = ($value['employee_id'] == $current_employee);
         $employee = DataObjectFactory::Factory('Employee');
         $employee->authorisationPolicy($employee->holiday_model());
         // Employee will not load if user does not have authorisation
         $employee->load($value['employee_id']);
         $authorisers = $employee->getAuthorisers($employee->holiday_model());
         $authoriser = in_array($current_employee, $authorisers);
         // Also need to check user's permissions for each holiday request
         // as to whether they can edit the requests for the employee
         $editable = $employee->isLoaded() && $access_allowed && ($authoriser || $value['status'] == 'W');
         //echo $value['employee'].' start_date:'	.$value['start_date'].' status:'.$value['status'].' all_day:'.$value['all_day'];
         $output_events[] = array('id' => $value['id'], 'title' => $value['employee'], 'allDay' => $value['all_day'] == 't', 'start' => strtotime($value['start_date']), 'end' => strtotime($value['end_date'] . ' 18:00:00'), 'className' => $colours[$value['status']], 'employee_id' => $value['employee_id'], 'status' => $value['status'], 'editable' => $editable, 'authoriser' => $authoriser, 'reason_declined' => $value['reason_declined']);
     }
     echo json_encode($output_events);
     exit;
 }
Ejemplo n.º 18
0
 private function checkPermissions(&$link)
 {
     if (isset($link['modules'])) {
         $modules = $link['modules'];
     } elseif (isset($link['module'])) {
         $modules = $link['module'];
     } else {
         $modules = '';
     }
     if (isset($link['controller'])) {
         $controller = $link['controller'];
     } else {
         $controller = '';
     }
     if (isset($link['action']) && strtolower($link['action']) == 'printdialog' && isset($link['printaction'])) {
         $action = $link['printaction'];
     } elseif (isset($link['action'])) {
         $action = $link['action'];
     } else {
         $action = '';
     }
     if (is_array($modules)) {
         $module = current($modules);
     } else {
         $module = $modules;
     }
     $ao = AccessObject::Instance();
     $pid = $ao->getCache($module, $controller, $action);
     if ($pid) {
         if (empty($link['pid'])) {
             $link['pid'] = $pid;
         }
         return TRUE;
     }
     if (empty($link['pid'])) {
         $link['pid'] = $ao->getPermission($modules, $controller, $action);
     }
     $pid = $link['pid'];
     if ($ao->hasPermission($modules, $controller, $action, $pid)) {
         $ao->saveCache($module, $controller, $action, $pid);
         return TRUE;
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 19
0
 public function Redirect()
 {
     $args = func_get_args();
     $arg_array = array('controller', 'action', 'module', 'other');
     $module = '';
     $controller = '';
     $action = '';
     if (is_array($args[0])) {
         $args = $args[0];
     }
     foreach ($args as $i => $arg) {
         ${$arg_array[$i]} = $arg;
     }
     Flash::Instance()->save();
     $url = '';
     $amp = '';
     $ao = AccessObject::Instance();
     $pid = $ao->getPermission($module, $controller, $action);
     if (!empty($pid)) {
         $url = 'pid=' . $pid;
         $amp = '&';
     }
     if (isset($module) && !empty($module)) {
         if (!is_array($module)) {
             $module = array($module);
         }
         $prefix = 'module=';
         foreach ($module as $m) {
             $url .= $amp . $prefix . $m;
             $prefix = 'sub' . $prefix;
             $amp = '&';
         }
     }
     if (!empty($controller)) {
         $url .= $amp . 'controller=' . $controller;
         $amp = '&';
     }
     if (!empty($action)) {
         $url .= $amp . 'action=' . $action;
         $amp = '&';
     }
     if (!empty($other)) {
         foreach ($other as $key => $value) {
             $url .= $amp . $key . '=' . $value;
             $amp = '&';
         }
     }
     $location = $url;
     if (!empty($location) && $location[0] == '&') {
         $location = substr($location, 1);
     }
     debug('RedirectHandler::Redirect ' . $location);
     //		echo 'RedirectHandler::Redirect '.$location.'<br>';
     $system = system::Instance();
     if (is_object($system->controller)) {
         if (is_array($system->controller->_data) && isset($system->controller->_data['password'])) {
             $system->controller->_data['password'] = '******';
         }
         audit(print_r($system->controller->_data, true) . print_r($system->flash, true));
     }
     audit('RedirectHandler::Redirect ' . $location);
     header('Location: ' . SERVER_ROOT . (!empty($location) ? '/?' . $location : ''));
     exit;
 }
Ejemplo n.º 20
0
function smarty_function_view_data($params, &$smarty)
{
    $attribute = $params['attribute'];
    $ddclass = $params['ddclass'];
    // no point in continuing now
    if (prettify($attribute) == 'EGS_HIDDEN_FIELD') {
        return '';
    }
    // aobve + top
    if (isset($params['label_position']) && in_array($params['label_position'], array('above', 'top'))) {
        $template_html = '<!-- %s --><dd id=%s class="wide">%s</dd>';
    } else {
        if ($ddclass) {
            $template_html = '<dt>%s</dt><dd id=%s class=%4$s>%s</dd>';
        } else {
            $template_html = '<dt>%s</dt><dd id=%s>%s</dd>';
        }
    }
    $with =& $smarty->getTemplateVars('with');
    if (!empty($params['model'])) {
        $model =& $params['model'];
    } else {
        $model = $with['model'];
        // default?
    }
    if (!empty($params['modifier'])) {
        $modifier = $params['modifier'];
    } else {
        if (isset($with['modifier'])) {
            $modifier = $with['modifier'];
        }
    }
    if (isset($params['value']) || empty($attribute) && $params['value'] == NULL) {
        $value = $params['value'];
    } else {
        if ($model->isField($attribute)) {
            $field = $model->getField($attribute);
            $value = $model->getFormatted($attribute);
        }
        if (empty($value)) {
            $value = $model->{$attribute};
        }
        if (substr($attribute, -2) == '()') {
            $attribute = substr($attribute, 0, -2);
            $field->is_safe = TRUE;
            $value = call_user_func(array($model, $attribute));
        }
        if (method_exists($value, '__toString')) {
            $value = $value->__toString();
        }
    }
    // use the value as the css class instead of the class string from the view
    if ($ddclass == 'show_value') {
        $ddclass = strtolower($value);
    }
    if ($attribute == 'rag_status()') {
        var_dump($value);
    }
    if (empty($value) && $model->isEnum($attribute)) {
        $values = $model->getEnumOptions($attribute);
        $value = $values[$value];
    }
    if ($model->isField($attribute)) {
        $field = $model->getField($attribute);
        $tag = $field->tag;
    }
    if (empty($tag)) {
        $tag = prettify($attribute);
    }
    if (isset($params['label'])) {
        $tag = prettify($params['label']);
    }
    if (isset($params['type']) && $params['type'] == "percentage") {
        $value .= "&#37;";
    }
    // TODO: Could this be data driven?
    //		 Should this be pre-populated with standard stuff, or removed
    //		 and handled dynamically via 'belongs_to'; see below?
    // Probably should create this as a structure array that builds up the
    // link to be used below.
    $temp_lookups = array('employee' => 'hr', 'company' => 'contacts', 'person' => 'contacts', 'project' => 'projects', 'originator_person' => 'contacts', 'originator_company' => 'contacts', 'opportunity' => 'crm');
    if (str_replace(' ', '', $value) == '') {
        $value = '<span class="blank">-</span>';
    } elseif (isset($_SESSION['cache'][get_class($model)][$attribute]) && !empty($model->{$_SESSION['cache'][get_class($model)][$attribute]['fk_field']})) {
        $value = link_to(array('pid' => $_SESSION['cache'][get_class($model)][$attribute]['pid'], 'module' => $_SESSION['cache'][get_class($model)][$attribute]['module'], 'controller' => $_SESSION['cache'][get_class($model)][$attribute]['controller'], 'action' => 'view', $_SESSION['cache'][get_class($model)][$attribute]['id_field'] => $model->{$_SESSION['cache'][get_class($model)][$attribute]['fk_field']}, 'value' => h($value)));
    } elseif (isset($params['link_to'])) {
        $link = $params['link_to'];
        $id_candidate = $attribute . '_id';
        if ($model->isField($id_candidate)) {
            $id = $model->{$id_candidate};
            $link = str_replace('__ID__', $id, $link);
        }
        if (!is_array($link)) {
            $link = str_replace(array('{', '}'), '', $link);
            $link = json_decode('{' . $link . '}', TRUE);
        }
        $link['value'] = $value;
        $value = link_to($link);
    } elseif ($attribute == 'email') {
        /* This auto links to emails */
        $link = '<a class="mailto" href="mailto:' . $value . '">%s</a>';
        $value = sprintf($link, $value);
    } elseif ($attribute == 'postcode') {
        // This auto links to google maps for postcodes
        $link = '<a class="maps_link" href="http://maps.google.co.uk/maps?f=q&hl=en&q=%s">%s</a>';
        $value = sprintf($link, $value, $value);
    } else {
        if (isset($model->belongsToField[$attribute])) {
            // This is probably a fk id field so need to translate the id value
            // to the fk identifier value via the belongsTo link
            $belongs_field = strtolower($model->belongsToField[$attribute]);
            $belongs_model = strtolower($model->belongsTo[$belongs_field]['model']);
            $fk_field = $model->belongsTo[$belongs_field]['field'];
            // Should already have the value from above; if not, try getting it again
            if (empty($value)) {
                $value = $model->{$belongs_field};
            }
        }
        if (isset($model->belongsTo[$attribute])) {
            // This is a fk field name via a belongsTo link
            $belongs_model = strtolower($model->belongsTo[$attribute]['model']);
            $fk_field = $model->belongsTo[$attribute]['field'];
        }
        if (!empty($belongs_model)) {
            if (!isset($temp_lookups[$belongs_model])) {
                $modulecomponent = DataObjectFactory::Factory('ModuleComponent');
                $modulecomponent->loadBy(array('name', 'type'), array($belongs_model . 'scontroller', 'C'));
                if ($modulecomponent->isLoaded()) {
                    $temp_lookups[$attribute] = $modulecomponent->module->name;
                }
            }
        } else {
            $belongs_model = $attribute;
        }
        if (isset($temp_lookups[$attribute]) || isset($temp_lookups[$params['fk']])) {
            if (isset($params['fk_field'])) {
                $fk_field = $params['fk_field'];
            } elseif (empty($fk_field)) {
                $fk_field = $attribute . '_id';
            }
            if (isset($params['fk'])) {
                $belongs_model = $params['fk'];
                $module = $temp_lookups[$params['fk']];
            } else {
                $module = $temp_lookups[$attribute];
            }
            if (method_exists($belongs_model . 'scontroller', 'view') && !is_null($model->{$fk_field})) {
                // check if the user is allowed to view the related link
                $ao = AccessObject::Instance();
                $pid = $ao->getPermission($module, $belongs_model . 's', 'view');
                //				$allowed	= $ao->hasPermission($module, $belongs_model . 's', 'view', $pid);
                // if the user is allowed to view the link, append a double right arrow
                //				$suffix = ($allowed === TRUE ? ' &raquo;' : '');
                $link_model = DataObjectFactory::Factory($belongs_model);
                $value = link_to(array('module' => $module, 'controller' => $belongs_model . 's', 'action' => 'view', $link_model->idField => $model->{$fk_field}, 'value' => h($value)));
                $_SESSION['cache'][get_class($model)][$attribute] = array('pid' => $pid, 'module' => $module, 'controller' => $belongs_model . 's', 'id_field' => $link_model->idField, 'fk_field' => $fk_field);
            }
        } elseif (isset($modifier)) {
            $value = call_user_func($modifier, $value);
        } else {
            if (!$field->is_safe) {
                $value = h($value, ENT_QUOTES);
            }
        }
    }
    if (prettify($attribute) == 'EGS_HIDDEN_FIELD') {
        return '';
    }
    $template_id = isset($params['id']) ? $params['id'] : $attribute;
    $template_id = empty($template_id) ? '' : get_class($model) . '_' . $template_id;
    return sprintf($template_html, $tag, $template_id, $value, $ddclass);
}
Ejemplo n.º 21
0
function isModuleAdmin($name = null)
{
    return true;
    $router = RouteParser::Instance();
    if (isset($name)) {
        $module = $name;
    } else {
        $module = $router->dispatch('module');
    }
    if (isset($_SESSION['module_admins'])) {
        $cache = $_SESSION['module_admins'];
    } else {
        $cache = array();
    }
    if (!isset($cache[$module])) {
        $access = AccessObject::Instance();
        $db = DB::Instance();
        $roles_string = implode(',', $access->roles);
        //		foreach ($access->roles as $role) {
        //			$roles_string.=$role.',';
        //		}
        //		$roles_string=rtrim($roles_string,',');
        $query = 'SELECT module_name FROM module_admins WHERE role_id IN (' . $roles_string . ') AND module_name=' . $db->qstr($module);
        debug('lib::isModuleAdmin ' . $query);
        $module = $db->GetOne($query);
        if (!empty($module) && $module !== FALSE) {
            $cache[$module] = TRUE;
        } else {
            foreach ($access->tree as $treenode) {
                if ($treenode['name'] == 'egs') {
                    $cache[$module] = TRUE;
                }
            }
            $cache[$module] = FALSE;
        }
    }
    $_SESSION['module_admins'][$module] = $cache[$module];
    return $cache[$module];
}
Ejemplo n.º 22
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     $company = $this->_uses['Lead'];
     if (isset($this->_data['Lead'][$company->idField]) && !empty($this->_data['Lead'][$company->idField])) {
         $company->load($this->_data['Lead'][$company->idField]);
         if ($company === false) {
             echo 'Could not load Company for id=' . $this->_data['Lead'][$person->idField] . ' - Abandoned<br>';
             sendBack();
         }
     }
     $db =& DB::Instance();
     $db->StartTrans();
     $partycontactmethod = DataObjectFactory::Factory('PartyContactMethod');
     foreach ($partycontactmethod->getEnumOptions('type') as $key => $type) {
         if (isset($this->_data[$type]['PartyContactMethod']) && isset($this->_data[$type]['Contactmethod']) && empty($this->_data[$type]['Contactmethod']['contact'])) {
             if (!empty($this->_data[$type]['PartyContactMethod'][$partycontactmethod->idField])) {
                 $partycontactmethod->delete($this->_data[$type]['PartyContactMethod'][$partycontactmethod->idField], $errors);
             }
             unset($this->_data[$type]);
         }
     }
     if (count($errors) == 0 && parent::save('Lead')) {
         foreach ($this->saved_models as $model) {
             if (isset($model['Lead'])) {
                 $company = $model['Lead'];
                 break;
             }
         }
         $this->company_id = $company->id;
         if (isset($this->_data['Lead']['crm'])) {
             $crm_data = $this->_data['Lead']['crm'];
             $ao =& AccessObject::Instance(EGS_USERNAME);
             if ($ao->hasPermission('crm')) {
                 $crm_data['company_id'] = $company->{$company->idField};
                 parent::save('CompanyCrm', $crm_data);
             }
         }
         $category = DataObjectFactory::Factory('CompanyInCategories');
         $current_categories = $category->getCategoryID($company->{$company->idField});
         $check_categories = array();
         if (isset($this->_data['ContactCategories'])) {
             $delete_categories = array_diff($current_categories, $this->_data['ContactCategories']['category_id']);
             $insert_categories = array_diff($this->_data['ContactCategories']['category_id'], $current_categories);
         }
         $result = TRUE;
         if (!empty($delete_categories)) {
             $result = $category->delete(array_keys($delete_categories), $errors);
         }
         if (!empty($insert_categories) && $result) {
             $result = $category->insert($insert_categories, $company->{$company->idField});
         }
         if ($result) {
             $db->CompleteTrans();
             sendTo($this->name, 'view', $this->_modules, array($company->idField => $company->{$company->idField}));
         }
     }
     // Errors
     $flash->addErrors($errors);
     $db->FailTrans();
     $db->CompleteTrans();
     $this->refresh();
 }
Ejemplo n.º 23
0
function smarty_block_grid_cell($params, $content, &$smarty, $repeat)
{
    if (!empty($content)) {
        // no point continuing if we're dealing with an id field
        if (substr($params['field'], -2) == 'id') {
            return '';
        }
        // set vars
        $attrs = array();
        $id = $smarty->getTemplateVars('gridrow_id');
        $with =& $smarty->getTemplateVars('with');
        if (!empty($params['model'])) {
            $model =& $params['model'];
        } else {
            $model = $with['model'];
        }
        if ($model->getField($params['field'])->type !== 'html' && !isset($params['no_escape'])) {
            $content = h(trim($content));
        }
        if ($params['cell_num'] == 1) {
            if ($smarty->getTemplateVars('clickaction') != 'none') {
                $link = array();
                $self = $smarty->getTemplateVars('self');
                if ($smarty->getTemplateVars('clickmodule')) {
                    $link['modules'] = $smarty->getTemplateVars('clickmodule');
                } else {
                    $link['modules'] = $self['modules'];
                }
                if ($smarty->getTemplateVars('clickcontroller')) {
                    $clickcontroller = $smarty->getTemplateVars('clickcontroller');
                } else {
                    $clickcontroller = $self['controller'];
                }
                if ($params['collection']->clickcontroller) {
                    $clickcontroller = $params['collection']->clickcontroller;
                }
                $link['controller'] = $clickcontroller;
                if ($params['collection']->editclickaction) {
                    $link['action'] = $params['collection']->editclickaction;
                } else {
                    $link['action'] = $smarty->getTemplateVars('clickaction');
                }
                if ($smarty->getTemplateVars('linkfield')) {
                    $linkfield = $smarty->getTemplateVars('linkfield');
                } else {
                    $linkfield = $model->idField;
                }
                if ($smarty->getTemplateVars('linkvaluefield')) {
                    $link[$linkfield] = $model->{$smarty->getTemplateVars('linkvaluefield')};
                } else {
                    $link[$linkfield] = $model->{$linkfield};
                }
                if ($smarty->getTemplateVars('linkdata')) {
                    foreach ($smarty->getTemplateVars('linkdata') as $field => $value) {
                        $link[$field] = $value;
                    }
                }
                foreach ($params as $field => $value) {
                    if (substr($field, 0, 1) == '_' && $model->isField(substr($field, 1))) {
                        $link[substr($field, 1)] = $value;
                    }
                }
                $link['value'] = $content;
                if (empty($link['pid'])) {
                    $ao = AccessObject::Instance();
                    $link['pid'] = $ao->getPermission($link['modules'], $link['controller'], $link['action']);
                }
                if (!empty($link['pid']) && !empty($link['action'])) {
                    $content = link_to($link, $data = true);
                    $_SESSION['cache'][get_class($model)][$params['field']] = array('pid' => $link['pid'], 'modules' => $link['modules'], 'controller' => $link['controller'], 'action' => $link['action']);
                }
            }
        } elseif (!empty($content) && isset($_SESSION['cache'][get_class($model)][$params['field']])) {
            $content = link_to(array('pid' => $_SESSION['cache'][get_class($model)][$params['field']]['pid'], 'module' => $_SESSION['cache'][get_class($model)][$params['field']]['module'], 'controller' => $_SESSION['cache'][get_class($model)][$params['field']]['controller'], 'action' => 'view', $_SESSION['cache'][get_class($model)][$params['field']]['id_field'] => $model->{$_SESSION['cache'][get_class($model)][$params['field']]['fk_field']}, 'value' => $content));
        } elseif (!empty($content)) {
            // If the field is in a belongsTo FK link, then enable the link
            // if the user has access to the target function
            // TODO: this code is copied from view_data so could be moved to generic function?
            $temp_lookups = array();
            if (isset($model->belongsToField[$params['field']])) {
                $belongs_field = strtolower($model->belongsToField[$params['field']]);
                $belongs_model = strtolower($model->belongsTo[$belongs_field]['model']);
                $fk_field = $model->belongsTo[$belongs_field]['field'];
            }
            if (isset($model->belongsTo[$params['field']])) {
                $belongs_model = strtolower($model->belongsTo[$params['field']]['model']);
                $fk_field = $model->belongsTo[$params['field']]['field'];
            }
            if (!empty($belongs_model)) {
                if (!isset($temp_lookups[$belongs_model])) {
                    $modulecomponent = DataObjectFactory::Factory('ModuleComponent');
                    $modulecomponent->loadBy(array('name', 'type'), array($belongs_model . 'scontroller', 'C'));
                    if ($modulecomponent->isLoaded()) {
                        $temp_lookups[$params['field']] = $modulecomponent->module->name;
                    }
                }
            } else {
                $belongs_model = $params['field'];
            }
            if (isset($temp_lookups[$params['field']]) || isset($temp_lookups[$params['fk']])) {
                if (isset($params['fk_field'])) {
                    $fk_field = $params['fk_field'];
                } elseif (empty($fk_field)) {
                    $fk_field = $params['field'] . '_id';
                }
                if (isset($params['fk'])) {
                    $belongs_model = $params['fk'];
                    $module = $temp_lookups[$params['fk']];
                } else {
                    $module = $temp_lookups[$params['field']];
                }
                if (method_exists($belongs_model . 'scontroller', 'view') && !is_null($model->{$fk_field})) {
                    $ao = AccessObject::Instance();
                    $pid = $ao->getPermission($module, $belongs_model . 's', 'view');
                    if (!empty($pid)) {
                        $link_model = DataObjectFactory::Factory($belongs_model);
                        $content = link_to(array('pid' => $pid, 'module' => $module, 'controller' => $belongs_model . 's', 'action' => 'view', $link_model->idField => $model->{$fk_field}, 'value' => $content));
                        $_SESSION['cache'][get_class($model)][$params['field']] = array('pid' => $pid, 'module' => $module, 'controller' => $belongs_model . 's', 'id_field' => $link_model->idField, 'fk_field' => $fk_field);
                    }
                }
            }
        }
        if ($params['field'] == $smarty->getTemplateVars('wide_column')) {
            $attrs['class'][] = 'wide_column';
        }
        if ($model->getField($params['field'])->type == 'numeric') {
            $attrs['class'][] = 'numeric';
        }
        if ($model->getField($params['field'])->type == 'bool') {
            $attrs['class'][] = 'icon';
            $content = '<img src="/themes/default/graphics/' . ($model->{$params['field']} == 't' ? 'true' : 'false') . '.png" alt="' . ($model->{$params['field']} == 't' ? 'true' : 'false') . '" />';
        }
        if (isset($params['class'])) {
            $attrs['class'][] = $params['class'];
        }
        $attrs['class'][] = 'row_' . $params['field'];
        if ($params['field'] == 'email') {
            $email = $model->getField($params['field'])->value;
            if (!empty($email)) {
                $content = '<a href="mailto:' . $email . '">' . $content . '</a>';
            }
        }
        if ($params['field'] == 'company') {
            $field = $model->companydetail->is_lead == 't' ? 'lead' : $params['field'];
        } else {
            $field = $params['field'];
        }
        if (($params['field'] == 'company' || $params['field'] == 'person') && !is_null($model->{$params['field'] . '_id'})) {
            $content = sprintf('<a href="/?module=contacts&controller=%s&action=view&id=%s">%s</a>', $field . 's', $model->{$params['field'] . '_id'}, $content);
        }
        // convert attrs array to a string
        $attrs = build_attribute_string($attrs);
        return '<td ' . $attrs . ' >' . $content . '</td>' . "\n";
    }
}
Ejemplo n.º 24
0
 public function index()
 {
     // dynamically generate the quick links from the permissions for the selected module
     $eglet = new SimpleMenuEGlet(new SimpleRenderer());
     $eglet->setMenuData($this->dashboard_module, $system->pid);
     $eglet->setSmarty($this->view);
     if (count($eglet->getContents()) > 0) {
         $this->view->set('eglets', array('Quick Links' => $eglet));
     }
     #$cache			= Cache::Instance();
     #$eglet_store	= $cache->get(array('eglet_store', $this->module));
     // ATTN: we're avoiding the cache because eglets are appearing (and not appearing)
     // where they should be. it seems the module grouping isn't actually working
     $eglet_store = FALSE;
     $ao =& AccessObject::Instance(EGS_USERNAME);
     if (FALSE === $eglet_store) {
         // get user's uzlet preferences
         $prefs = UserPreferences::Instance(EGS_USERNAME);
         $user_uzlets = $prefs->getPreferenceValue('dashboard_contents', $this->dashboard_module);
         $user_uzlets = is_array($user_uzlets) ? array_flip($user_uzlets) : array();
         // discover what uzlet_id's belong to the module we're working with
         $uzlets = new UzletCollection();
         $sh = new SearchHandler($uzlets, FALSE);
         if (count($user_uzlets) > 0) {
             // get the uzlet details for the user's uzlet preferences
             $db = DB::Instance();
             $uzlet_names = array();
             foreach ($user_uzlets as $name => $value) {
                 $uzlet_names[] = $db->qstr($name);
             }
             $sh->addConstraint(new Constraint('name', 'in', '(' . implode(',', $uzlet_names) . ')'));
         } else {
             // user preferences are not set, get the default(preset) uzlets for the module
             $sh->addConstraint(new Constraint('preset', 'is', TRUE));
             if ($this->dashboard_module == 'dashboard') {
                 $sh->addConstraint(new Constraint('dashboard', 'is', TRUE));
                 // only include uzlets for modules the user has access to
                 foreach ($ao->permissions as $permission) {
                     if ($permission['type'] == 'm' && !empty($permission['module_id'])) {
                         $modules[$permission['module_id']] = $permission['module_id'];
                     }
                 }
                 if (count($modules) > 0) {
                     $sh->addConstraint(new Constraint('module_id', 'in', '(' . implode(',', $modules) . ')'));
                 } else {
                     $sh->addConstraint(new Constraint('module_id', '=', -1));
                 }
             } else {
                 $sh->addConstraint(new Constraint('module', '=', $this->dashboard_module));
             }
         }
         $sh->addConstraint(new Constraint('enabled', 'is', TRUE));
         $rows = $uzlets->load($sh, null, RETURN_ROWS);
         $uzlets = array();
         if (!empty($rows)) {
             if (empty($user_uzlets)) {
                 // no user uzlet preferences so set uzlets to the default(preset) for the module
                 foreach ($rows as $uzlet) {
                     $uzlets[$uzlet['name']] = $uzlet;
                 }
             } else {
                 // Preserve order of user's uzlet preferences
                 foreach ($rows as $uzlet) {
                     if (isset($user_uzlets[$uzlet['name']])) {
                         $user_uzlets[$uzlet['name']] = $uzlet;
                     }
                 }
                 // Remove any user's uzlet preferences that are no longer valid
                 foreach ($user_uzlets as $name => $uzlet) {
                     if (!is_array($uzlet)) {
                         unset($user_uzlets[$name]);
                     }
                 }
                 $uzlets = $user_uzlets;
             }
         }
         $this->view->set('uzlets', $uzlets);
     }
     showtime('pre-pop');
     $this->view->set('can_edit', $ao->can_manage_uzlets());
 }
Ejemplo n.º 25
0
 function getDashboardContents($username = EGS_USERNAME, $dashboard_module = '', $pid = '')
 {
     // Get list of modules the user has access to
     $ao =& AccessObject::Instance($username);
     $usermodules = $ao->getUserModules($username);
     $modules = array();
     $contents = array();
     if (!empty($usermodules)) {
         $db = DB::Instance();
         if ($dashboard_module != 'dashboard' && !empty($pid)) {
             $parent = $pid;
         }
         foreach ($usermodules as $module_permission) {
             // Get user's selected uzlets for the current module
             $contents[$module_permission['permission']] = $this->getPreferenceValue('dashboard_contents', $module_permission['permission']);
             if (empty($parent) || $parent == $module_permission['permissionsid'] || $parent == $module_permission['parent_id']) {
                 $modules[$module_permission['permissionsid']] = $db->qstr($module_permission['permission']);
             }
         }
     }
     // now load the uzlets that are available to the user
     // for this module or modules they have access to
     $uzlets = new UzletCollection();
     $sh = new SearchHandler($uzlets, FALSE);
     if (empty($modules)) {
         $sh->addConstraint(new Constraint('module', '=', $dashboard_module));
         $check_modules = false;
     } else {
         $sh->addConstraint(new Constraint('module', 'in', '(' . implode(',', $modules) . ')'));
         $check_modules = true;
     }
     if ($dashboard_module == 'dashboard') {
         $sh->addConstraint(new Constraint('dashboard', 'is', TRUE));
         $check_modules = true;
     }
     $sh->addConstraint(new Constraint('enabled', 'is', TRUE));
     $sh->setOrderby(array('module', 'title'));
     $rows = $uzlets->load($sh, null, RETURN_ROWS);
     // Now construct uzlet list for display
     $available = array();
     $selected = array();
     if (count($rows) > 0) {
         foreach ($rows as $uzlet) {
             if (is_array($contents) && !empty($contents[$uzlet['module']]) && in_array($uzlet['name'], $contents[$uzlet['module']])) {
                 //if the user has picked the EGlet previously, then it belongs in 'selected' (setting the index preserves the ordering)
                 $selected[$uzlet['module']][array_search($uzlet['name'], $contents[$uzlet['module']])] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
             } elseif (empty($contents[$uzlet['module']]) && $uzlet['preset'] == 't') {
                 //if they haven't picked any EGlets, and the EGlet is marked as default for the current module then it's 'selected'
                 $selected[$uzlet['module']][] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
             } else {
                 $available[$uzlet['module']][$uzlet['module']][$uzlet['name']] = prettify($uzlet['title']);
             }
             if ($uzlet['module'] != 'dashboard') {
                 if (is_array($contents) && !empty($contents['dashboard']) && in_array($uzlet['name'], $contents['dashboard'])) {
                     //if the user has picked the EGlet previously, then it belongs in 'selected' (setting the index preserves the ordering)
                     $selected['dashboard'][array_search($uzlet['name'], $contents['dashboard'])] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
                 } elseif ($uzlet['dashboard'] == 't') {
                     // uzlet can appear on Dashboard so add to dashboard available list
                     $available['dashboard'][$uzlet['module']][$uzlet['name']] = prettify($uzlet['title']);
                 }
             }
         }
     }
     ksort($available);
     foreach ($available as &$module) {
         ksort($module);
         if (is_array($module)) {
             foreach ($module as &$detail) {
                 if (is_array($detail)) {
                     asort($detail);
                 } else {
                     asort($module);
                     break;
                 }
             }
         }
     }
     ksort($selected);
     return array('available' => $available, 'selected' => $selected);
 }