/** * Contruct controller and execute specific action * * @access public * @param string $controller_name * @param string $action * @return null */ static function executeAction($controller_name, $action) { $max_users = config_option('max_users'); if ($max_users && Contacts::count() > $max_users) { echo lang("error").": ".lang("maximum number of users exceeded error"); return; } ajx_check_login(); Env::useController($controller_name); $controller_class = Env::getControllerClass($controller_name); if(!class_exists($controller_class, false)) { throw new ControllerDnxError($controller_name); } // if $controller = new $controller_class(); if(!instance_of($controller, 'Controller')) { throw new ControllerDnxError($controller_name); } // if if (is_ajax_request()) { // if request is an ajax request return a json response // execute the action $controller->setAutoRender(false); $controller->execute($action); // fill the response $response = AjaxResponse::instance(); if (!$response->hasCurrent()) { // set the current content $response->setCurrentContent("html", $controller->getContent(), page_actions(), ajx_get_panel()); } $response->setEvents(evt_pop()); $error = flash_pop('error'); $success = flash_pop('success'); if (!is_null($error)) { $response->setError(1, clean($error)); } else if (!is_null($success)) { $response->setError(0, clean($success)); } // display the object as json tpl_assign("object", $response); $content = tpl_fetch(Env::getTemplatePath("json")); tpl_assign("content_for_layout", $content); TimeIt::start("Transfer"); if (is_iframe_request()) { tpl_display(Env::getLayoutPath("iframe")); } else { tpl_display(Env::getLayoutPath("json")); } TimeIt::stop(); } else { return $controller->execute($action); } } // executeAction
/** * @author Ignacio Vazquez <elpepe.uy at gmail dot com> * Handle quick add submit */ function quick_add() { if (array_var($_GET, 'current') == 'overview-panel') { ajx_current("reload"); }else { ajx_current("empty"); } //---------- REQUEST PARAMS -------------- // $_POST = Array ( // [member] => Array ( // [name] => pepe 333 // [dimension_id] => 1 // [parent_member_id] => 0 // [dimension_id] => 19 // ) // [contact] => Array ( // [email] => slkdjflksjdflksdf@kldsjflkdf.com // [user] => Array ( // [create-user]=>on // [type] => 25 // [first_name] => // [surname] => // ) //---------------------------------------- // Init variables $max_users = config_option('max_users'); if ($max_users && (Contacts::count() >= $max_users)) { flash_error(lang('maximum number of users reached error')); ajx_current("empty"); return; } if (!can_manage_security(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $email = trim(array_var(array_var($_POST, 'contact'),'email')) ; $member = array_var($_POST, 'member'); $name = array_var($member, 'name'); $firstName = trim(array_var(array_var($_POST, 'contact'),'first_name')); $surname = trim(array_var(array_var($_POST, 'contact'),'surname')); $parentMemberId = array_var($member, 'parent_member_id'); $objectType = ObjectTypes::findById(array_var($member, 'object_type_id'))->getName(); // 'person', 'company' $dimensionId = array_var($member, 'dimension_id'); $company = array_var(array_var(array_var($_POST, 'contact'),'user'),'company_id'); // Create new instance of Contact and set the basic fields $contact = new Contact(); $contact->setObjectName($name); if ($firstName) { $contact->setFirstName($firstName); }else{ $contact->setFirstName($name); } if ($surname) { $contact->setSurname($surname); } $contact->setCompanyId($company); $contact->setIsCompany($objectType == "company"); if ($parentMemberId){ if ( $companyId = Members::findById($parentMemberId)->getObjectId()) { $contact->setCompanyId($companyId); } } // Save Contact try { DB::beginWork(); $contact->save(); if ($email && is_valid_email($email)) { if (!Contacts::validateUniqueEmail($email)) { DB::rollback(); flash_error(lang("email address must be unique")); return false; }else{ if (!array_var (array_var(array_var($_POST, 'contact'),'user'), 'create-user')) { $contact->addEmail($email, 'personal', true); } flash_success(lang("success add contact", $contact->getObjectName())); } } // User settings $user = array_var(array_var($_POST, 'contact'),'user'); $user['username'] = str_replace(" ","",strtolower($name)) ; $this->createUserFromContactForm($user, $contact->getId(), $email); // Reload contact again due to 'createUserFromContactForm' changes Hook::fire("after_contact_quick_add", Contacts::instance()->findById($contact->getId()), $ret); DB::commit(); }catch (Exception $e){ DB::rollback(); flash_error($e->getMessage()); } // Reload evt_add("reload dimension tree", array('dim_id' => $dimensionId)); }
<?php set_page_title(lang('members')); if(Contact::canAddUser(logged_user())) { add_page_action(lang('add user'), owner_company()->getAddUserUrl(), 'ico-add',null,null,true); } // if ?> <div class="adminUsersList" style="height:100%;background-color:white"> <div class="adminHeader"> <div class="adminTitle"><?php echo lang('users') . (config_option('max_users')?(' (' . Contacts::count() .' / ' . config_option('max_users') . ')'):'') ?></div> </div> <div class="adminSeparator"></div> <div class="adminMainBlock"> <?php foreach ($users_by_company as $company_row){ $company = $company_row['details']; $users = $company_row['users']; if (count($users) == 0) continue; tpl_assign('users', $users); tpl_assign('company', $company); ?> <div style='padding-bottom:20px;max-width:700px'> <div style="padding:10px;padding-bottom:13px;background-color:#D7E5F5"> <h1 style="font-size:140%;font-weight:bold"><a class="internalLink" href="<?php echo ($company instanceof Contact ? $company->getCardUrl() : "#") ?>"><?php echo ($company instanceof Contact ? clean($company->getObjectName()) : lang('without company')) ?></a></h1> <div style="float:right;" id="companypagination<?php echo ($company instanceof Contact ? $company->getId() : "0"); ?>"></div> </div> <div id="usersList" style="border:1px solid #DDD"> <?php $this->includeTemplate(get_template_path('list_users', 'administration')); ?> </div></div>
/** * Return number of company users * * @access public * @param void * @return integer */ function countUsers() { return Contacts::count('`company_id` = ' . DB::escape($this->getId())); }
<?php set_page_title(lang('members')); if (Contact::canAddUser(logged_user())) { add_page_action(lang('add user'), owner_company()->getAddUserUrl(), 'ico-add', null, null, true); } // if ?> <div class="adminUsersList" style="height:100%;background-color:white"> <div class="coInputHeader"> <div> <div class="coInputName"> <div class="coInputTitle"> <?php echo lang('users') . (config_option('max_users') ? ' (' . Contacts::count() . ' / ' . config_option('max_users') . ')' : ''); ?> </div> </div> <div class="clear"></div> </div> </div> <div class="adminMainBlock"> <?php foreach ($users_by_company as $company_row) { $company = $company_row['details']; $users = $company_row['users']; if (count($users) == 0) { continue; } tpl_assign('users', $users);
function get_contacts_for_selector() { ajx_current("empty"); $name_condition = ""; $name_filter = trim(array_var($_REQUEST, 'query')); if ($name_filter != "") { $name_condition = " AND o.name LIKE '%{$name_filter}%'"; } // by default list only contacts $type_condition = " AND is_company=0"; $extra_conditions = ""; if ($filters = array_var($_REQUEST, 'filters')) { $filters = json_decode($filters, true); foreach ($filters as $col => $val) { if (Contacts::instance()->columnExists($col)) { $extra_conditions .= " AND " . DB::escapeField($col) . " = " . DB::escape($val); } else { if ($col == 'is_user') { $extra_conditions .= " AND `user_type`" . ($val == 1 ? " > 0" : " = 0"); } else { if ($col == 'has_permissions') { $extra_conditions .= " AND `user_type`>0 AND EXISTS(\r\n\t\t\t\t\t\t\tSELECT * FROM " . TABLE_PREFIX . "contact_member_permissions cmp\r\n\t\t\t\t\t\t\tWHERE cmp.permission_group_id IN (SELECT x.permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups x WHERE x.contact_id=o.id)\r\n\t\t\t\t\t\t\t\tAND cmp.member_id='{$val}'\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT tp.object_type_id FROM " . TABLE_PREFIX . "tab_panels tp WHERE tp.enabled=0)\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT oott.id FROM " . TABLE_PREFIX . "object_types oott WHERE oott.name IN ('comment','template'))\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id IN (SELECT oott2.id FROM " . TABLE_PREFIX . "object_types oott2 WHERE oott2.type IN ('content_object','dimension_object'))\r\n\t\t\t\t\t\t)"; } else { if ($col == 'only_companies') { if ($val == 1) { $type_condition = " AND is_company=1"; } } else { if ($col == 'include_companies') { if ($val == 1) { $type_condition = ""; } } } } } } } } if ($plugin_filters = array_var($_REQUEST, 'plugin_filters')) { $plugin_filters = json_decode($plugin_filters, true); $plugin_conditions = ""; Hook::fire('contact_selector_plugin_filters', $plugin_filters, $plugin_conditions); $extra_conditions .= $plugin_conditions; } $info = array(); $pg_ids = logged_user()->getPermissionGroupIds(); if (count($pg_ids) > 0) { $permissions_condition = " AND (o.id=" . logged_user()->getId() . " OR EXISTS (SELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh WHERE sh.object_id=o.id AND group_id IN (" . implode(',', $pg_ids) . ")))"; $conditions = "o.trashed_by_id=0 AND o.archived_by_id=0 {$name_condition} {$permissions_condition} {$type_condition} {$extra_conditions}"; $query_params = array('condition' => $conditions, 'order' => 'o.name ASC'); $count = Contacts::count($conditions); $limit = 30; $query_params['limit'] = $limit; $contacts = Contacts::findAll($query_params); foreach ($contacts as $c) { $info[] = array("id" => $c->getId(), "name" => $c->getObjectName()); } if ($name_filter == "" && $count >= $limit) { //$info[] = array('id' => -1, 'name' => lang('write the first letters of the name or surname of the person to select')); $info[] = array('id' => -2, 'name' => '<a href="#" class="db-ico ico-expand" style="color:blue;text-decoration:underline;padding-left:20px;">' . lang('show more') . '</a>'); } } ajx_extra_data(array('contacts' => $info)); }