/** * (non-PHPdoc) * @see \FrontPanels\Interfaces\InterfacePanelsProcessor::processPanel() */ public function processPanel(FrontPanelsPanelEntity $objPanel) { //load user $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); //load user contacts $objContacts = $this->getContactsModel()->fetchContacts(array("regtbl_user" => $objUser->id)); $arr = array(); foreach ($objContacts as $objContact) { if (!is_numeric($objContact->id) || $objContact->id == "") { continue; } //end if $arr_contact["name"] = $objContact->fname . " " . $objContact->sname; $arr_contact["reference"] = $objContact->reference; $arr_contact["source"] = $objContact->source; $view_url = "<a href=\"" . $this->getViewUrlHelper()->url("front-contacts", array("action" => "view-contact", "id" => $objContact->id)) . "\" title=\"View Contact Information\" data-toggle=\"tooltip\">" . ICON_SMALL_PROFILE_HTML . "</a>"; $edit_url = "<a href=\"" . $this->getViewUrlHelper()->url("front-contacts", array("action" => "edit-contact", "id" => $objContact->id)) . "\" title=\"Edit Contact Information\" data-toggle=\"tooltip\">" . ICON_SMALL_MODIFY_HTML . "</a>"; $comms_url = "<a href=\"" . $this->getViewUrlHelper()->url("front-contacts", array("action" => "view-contact", "id" => $objContact->id)) . "\" class=\"contact_comms\" data-contact-id=\"" . $objContact->id . "\" title=\"Contact Communications\" data-toggle=\"tooltip\">" . ICON_SMALL_COMMS_HTML . "</a>"; $arr_contact["Links"] = $view_url . " " . $edit_url . " " . $comms_url; $arr[] = $arr_contact; } //end foreach $add_url = "<a href=\"" . $this->getViewUrlHelper()->url("front-contacts", array("action" => "create-contact")) . "\" title=\"Create a new Contact\" data-toggle=\"tooltip\"><span class=\"icon-button-very-large\">" . ICON_MEDIUM_ADD_HTML . "</a>"; //load table helper $objSimpleHTMLTable = new \FrontCore\ViewHelpers\FrontRenderSimpleHtmlTable(); $html = $objSimpleHTMLTable->generate("", array("Name", "Reference", "Source", $add_url), $arr); $objPanel->set("html", $html); return $objPanel; }
/** * (non-PHPdoc) * @see \FrontPanels\Interfaces\InterfacePanelsProcessor::processPanel() */ public function processPanel(FrontPanelsPanelEntity $objPanel) { //load user $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); $html = "<a href=\"" . $this->getViewUrlHelper()->url("front-contacts") . "\" title=\"Contacts\">" . ICON_XLARGE_CONTACTS_HTML . "</a>"; $objPanel->set("html", $html); return $objPanel; }
/** * Generate a standard view heading * @param string $header_html * @return string */ public function __invoke($arr_date) { //set options if (isset($arr_date["options"])) { foreach ($arr_date["options"] as $k => $v) { $this->{$k} = $v; } //end foreach } //end if //is the date specified? if (!isset($arr_date["date"]) || trim($arr_date["date"]) == "" || trim($arr_date['date']) == '0000-00-00 00:00:00' || trim($arr_date['date']) == '0000-00-00') { return FALSE; } //end if try { //create date object and check date is utc formatted $objDate = \DateTime::createFromFormat(\DateTime::RFC3339, $arr_date["date"]); //was the date received valid? if (!$objDate) { if ($this->bool_report_errors === TRUE) { trigger_error("Date '" . $arr_date['date'] . "' is not a valid UTC formatted date", E_USER_WARNING); return FALSE; } //end if } //end if //format date to requested format and apply user timezone $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); $timezone = $objUser->locale_timezone; if ($timezone == '') { //try profile defined timezone $timezone = $objUser->profile->settings->locale_timezone; } //end if if ($timezone != '') { $objTimezone = new \DateTimeZone($timezone); $objDate->setTimezone($objTimezone); } //end if $date = $objDate->format($this->output_format); return $date; } catch (\Exception $e) { if ($this->bool_report_errors === TRUE) { //ignore error trigger_error($e->getMessage(), E_USER_NOTICE); } //end if if ($this->bool_throw_exception === TRUE) { throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : " . $e->getMessage(), $e->getCode()); } //end if return $arr_date["date"]; } //end catch }
public function ajaxToggleFeedAction() { $i = $this->params()->fromQuery("i", 1); //load user session $objUser = FrontUserSession::isLoggedIn(); if ($i == 1 || $i == 0) { $objUser->user_news_feed_activity = $i; } else { $objUser->user_news_feed_activity = 1 - $objUser->user_news_feed_activity; } //end if exit; }
public function displayPanelsAction() { $this->layout("layout/dashboard"); //check if panels are enabled $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); if (!in_array("panels", $objUser->profile->plugins_enabled)) { return $this->redirect()->toRoute("front-contacts"); } //end if try { //load user session $objUserSession = new \Zend\Session\Container("user"); //load user panels $objUserPanels = $this->getFrontPanelsModel()->fetchUserPanels(); $arr_panels = array(); //preprocess some panels foreach ($objUserPanels as $objPanel) { //check if panel has been cached if (isset($objUserSession->arr_cached_processed_panels[$objPanel->get("fk_id_panels")])) { $obj = $this->getServiceLocator()->get("FrontPanels\\Entities\\FrontPanelsPanelEntity"); $obj->set($objUserSession->arr_cached_processed_panels[$objPanel->get("fk_id_panels")]); $arr_panels[] = $obj; continue; } //end if switch ($objPanel->get("panels_panel_type")) { case "icon": $objPanelOutput = $this->getFrontPanelsModel()->processUserPanel($objPanel->get("fk_id_panels"), array("panel_id" => $objPanel->get("fk_id_panels"), "panels_name" => $objPanel->get("panels_name"), "panels_categories_category" => $objPanel->get("panels_categories_category"), "panels_unique_identifier" => $objPanel->get("panels_unique_identifier"))); $objPanel->set("html", $objPanelOutput->get("html")); //cache user icon if (!isset($objUserSession->arr_cached_processed_panels)) { $objUserSession->arr_cached_processed_panels = array(); } //end if $objUserSession->arr_cached_processed_panels[$objPanel->get("fk_id_panels")] = $objPanel->getArrayCopy(); break; } //end switch $arr_panels[] = $objPanel; } //end foreach } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage("Panels could not be loaded"); return $this->redirect()->toRoute("front-contacts"); } //end catch return array("objUserPanels" => (object) $arr_panels); }
/** * View a communication online * Although comm_history_id and comm_id is optional, either one is created. comm_history_id takes precedence over the comm id * @param mixed $comm_history_id - Optional, where set, the comm will be processed as if sent to a contact * @param mixed $comm_id - Optional, where comm history id is not, the comm content will be produced without processing replace fields * @return stdClass */ public function viewCommOnline($comm_history_id, $comm_id) { //create the request object $objApiRequest = $this->getApiRequestModel(); //load authentication details $arr_data = array("comm_history_id" => $comm_history_id, "comm_id" => $comm_id); $arr_data["util"] = "view-comm-online"; //where the comm history id is not, us user is probably trying to preview the communication which requires a user session if ($comm_history_id == '' && !FrontUserSession::isLoggedIn()) { throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : You must be logged in the view this page", 500); } //end if //where comm history id is set, use util to authenticate the request regardless of user being logged in if ($comm_history_id != '') { $objRequestAuthentication = $this->setRequestLogin($arr_data); $objApiRequest->setAPIKey($objRequestAuthentication->api_key); } //end if //setup the object and specify the action $objApiRequest->setApiAction("utils/comms/view"); $objCommContent = $objApiRequest->performGETRequest($arr_data)->getBody()->data; return $objCommContent; }
/** * Request a full list of contacts * This is saved to a file in the background and cached for 30 minutes * This function bypasses the normal api request model and makes a direct request * @param string $action */ public function fetchContactsStream($action = '') { //trigger pre event $result = $this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, array()); /** * Set user details for request */ //load user session data $objUserSession = FrontUserSession::isLoggedIn(); //set file path $path = './data/cache/cache_streams/' . str_replace('-', '', $objUserSession->profile->profile_identifier); if (!is_dir($path)) { mkdir($path, 0755, TRUE); } //end if $csv_file = $path . '/' . $objUserSession->profile->profile_identifier . '-contacts.csv'; $csv_metadata_file = $path . '/' . $objUserSession->profile->profile_identifier . '-contacts.csv.metadata'; $arr_return = array('source_data_path' => $csv_file, 'source_metadata' => $csv_metadata_file); switch ($action) { case 'delete': @unlink($csv_file); @unlink($csv_metadata_file); break; } //end switch //check if data file exists if (is_file($csv_file) && is_file($csv_metadata_file)) { //check if file has expired $arr = unserialize(file_get_contents($csv_metadata_file)); if (!is_array($arr)) { @unlink($csv_file); @unlink($csv_metadata_file); } //end if if (time() > $arr['expires']) { @unlink($csv_file); @unlink($csv_metadata_file); } else { return $arr_return; } //end if } //end if //check if this is a user or site call if ($this->api_pword == "" || !$this->api_pword) { //try to extract from session if (is_object($objUserSession)) { $this->api_pword = $objUserSession->pword; } //end if } //end if //set api username if ($this->api_user == "" || !$this->api_user) { //is api key encoded? if (is_object($objUserSession)) { if (isset($objUserSession->api_key_encoded) && $objUserSession->api_key_encoded === TRUE) { $key = $this->getServiceLocator()->get("FrontCore\\Models\\FrontCoreSecurityModel")->decodeValue($objUserSession->uname); $this->api_user = $key; } else { //try to extract from session $this->api_user = $objUserSession->uname; } //end if } //end if } //end if //set api key if ($this->api_key == "" || !$this->api_key) { //is api key encoded? if (is_object($objUserSession)) { if (isset($objUserSession->api_key_encoded) && $objUserSession->api_key_encoded === TRUE) { $this->api_key = $this->getServiceLocator()->get("FrontCore\\Models\\FrontCoreSecurityModel")->decodeValue($objUserSession->api_key); } else { //try to extract from session $this->api_key = $objUserSession->api_key; } //end if } //end if } //end if require "./config/helpers/ob1.php"; $arr_set_headers = array(); foreach ($arr_headers as $k => $v) { $arr_set_headers[] = "{$k}: {$v}"; } //end foreach //load config $arr_config = $this->getServiceLocator()->get('config')['profile_config']; //build the url $arr_fields = array('reg_id', 'reg_id_encoded', 'fname', 'sname', 'comm_destinations_email', 'source', 'reference', 'datetime_created', 'datetime_updated', 'registration_status_status', 'registration_status_colour', 'user_uname', 'user_sname'); $url = $arr_config['api_request_location'] . '/api/contacts?qp_limit=all&qp_stream_output_csv=1&qp_disable_hypermedia=1&qp_export_fields=' . implode(',', $arr_fields); /** * We use curl, its just easier */ set_time_limit(0); $fp = fopen($csv_file, 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_set_headers); $data = curl_exec($ch); curl_close($ch); fclose($fp); //set metadata file_put_contents($csv_metadata_file, serialize(array('expires' => time() + 60 * 60))); //trigger pre event $result = $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array()); //return file paths return $arr_return; }
/** * Set unique identifier so profiles do not overwrite each other * @param string $key * @return string */ private function setIdentifier($key) { $objUser = FrontUserSession::isLoggedIn(); if (is_object($objUser) && isset($objUser->profile->profile_identifier) && $objUser->profile->profile_identifier != "") { return $objUser->profile->profile_identifier . "-" . $key; } //end if if (is_object($objUser) && is_numeric($objUser->site_id)) { return $objUser->site_id . "-" . $key; } //end if return $key; }
/** * Check if a user is logged in * If not, setup a session with the correct key for form submission to work * @param int $form_id * @return stdClass */ private function setUserLogin($form_id) { //check if user is logged into frontend $objUserSession = FrontUserSession::isLoggedIn(); if (!$objUserSession) { $cache_key = "ex_form_" . $form_id . "_" . $_SERVER["HTTP_HOST"] . "_key"; //check if data has been cached $objData = $this->getFormsCacheModel()->readFormCache($cache_key); if (!$objData || is_null($objData)) { //create the request object $objApiRequest = $this->getApiRequestModel(); //disable api session login $objApiRequest->setAPISessionLoginDisable(); //load master user details $arr_user = $this->getServiceLocator()->get("config")["master_user_account"]; //set api request authentication details $objApiRequest->setAPIKey($arr_user['apikey']); $objApiRequest->setAPIUser(md5($arr_user['uname'])); $objApiRequest->setAPIUserPword(md5($arr_user['pword'])); //setup the object and specify the action $objApiRequest->setApiAction("user/authenticate-form?debug_display_errors=1"); //set payload $arr_data = array("fid" => $form_id, "tstamp" => time(), 'key' => $arr_user['apikey']); $objData = $objApiRequest->performPOSTRequest($arr_data)->getBody(); //cache the data $this->getFormsCacheModel()->setFormCache($cache_key, $objData); } //end if return $objData->data; } //end function return FALSE; }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); //preload the Service Manager instance to the Service Manager Factory FrontCoreServiceProviderFactory::setInstance($e->getApplication()->getServiceManager()); /** * Register event listeners */ $eventsFrontCore = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreEvents"); $eventsFrontCore->registerEvents(); $eventsSystemForms = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreSystemFormEvents"); $eventsSystemForms->registerEvents(); //append app config to layout //load config $arr_config = $e->getApplication()->getServiceManager()->get("config"); $e->getViewModel()->setVariable("app_config", $arr_config); $e->getViewModel()->setVariable("cdn_url", $arr_config["cdn_config"]["url"]); /** * Check if user is logged in */ $sharedEvents = $eventManager->getSharedManager(); $sharedEvents->attach("*", 'dispatch', function ($e) { // fired when an ActionController under the namespace is dispatched. $controller = $e->getTarget(); //first check if user needs to be logged in if ($e->getRouteMatch()->getParam("user-bypass-login") === TRUE) { return; } //end if $arr_exclude_controllers = array("FrontUserLogin\\Controller\\IndexController"); //check for cli requests if (get_class($controller) == "FrontCLI\\Controller\\IndexController") { //check if module is activated $objModuleManager = $e->getApplication()->getServiceManager()->get('ModuleManager'); $arr_modules = $objModuleManager->getLoadedModules(); if (array_key_exists("FrontCLI", $arr_modules)) { return; } //end if } //end if if (strtolower(substr(get_class($controller), 0, 5)) == "front" && !in_array(get_class($controller), $arr_exclude_controllers) || strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") { //check if user is logged in if (!FrontUserSession::isLoggedIn()) { //redirect to login screen and set message $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); $flashMessenger->addInfoMessage("Please login to continue"); //redirect back to login page $target = $e->getTarget(); if (strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") { //home page, access service manager differently from event $serviceLocator = $target->getServiceManager(); } else { $serviceLocator = $target->getServiceLocator(); } //end if $url = $e->getRouter()->assemble(array("controller" => "FrontUserLogin\\Controller\\IndexController"), array('name' => 'front-user-login')); $response = $e->getResponse(); $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url)); $response->setStatusCode(302); $response->sendHeaders(); exit; } //end if } //end if }, 110); /** * Deal with flash messages that needs to be passed to the layout view */ $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function ($e) { $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); if ($flashMessenger->hasMessages()) { $e->getViewModel()->setVariable('flashMessages', $flashMessenger->getMessages()); } //end if if ($flashMessenger->hasErrorMessages()) { $e->getViewModel()->setVariable('flashMessages_errors', $flashMessenger->getErrorMessages()); } //end if if ($flashMessenger->hasInfoMessages()) { $e->getViewModel()->setVariable('flashMessages_info', $flashMessenger->getInfoMessages()); } //end if if ($flashMessenger->hasSuccessMessages()) { $e->getViewModel()->setVariable('flashMessages_success', $flashMessenger->getSuccessMessages()); } //end if }); /** * Log api calls */ if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1 || isset($_GET["debug_display_queries"]) && $_GET["debug_display_queries"] == 1) { //get shared event manager $sem = $e->getApplication()->getEventManager()->getSharedManager(); $sem->attach("*", "apiCallExecuted", function ($event) use($e) { $objApiData = $event->getParam("objApiData"); $objResponse = $event->getParam("objResponse"); $objApiData->rawResponse = $objResponse->getBody(); if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1) { $url = $objApiData->url; $response = $objApiData->rawResponse; $arr = $e->getViewModel()->getVariable("api_logs"); $arr[] = $objApiData; $arr[] = $response; $e->getViewModel()->setVariable("api_logs", $arr); } //end if }); } //end if /** * Start session */ session_start(); //load icon packs $this->setIconPacks(); }
public function getUserNativePreferencesForm($objController) { $objForm = new NativeUserPreferencesForm(); $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); //load contact profile forms $arr_forms = $this->getServiceLocator()->get("FrontContacts\\Models\\FrontContactsModel")->getContactProfileForm(); //set no option $arr_element_value_options = array(); $arr_element_value_options["none"] = "No Layout"; //create element options foreach ($arr_forms as $key => $form_name) { if (is_numeric($key)) { $arr_element_value_options[$key] = $form_name; } //end if } //end foreach $objForm->get("cpp_form_id")->setValueOptions($arr_element_value_options); $objForm->get("cpp_layout_id")->setValueOptions($arr_element_value_options); //set home page locations $arr_locations = array($objController->url()->fromRoute("front-contacts") => "My Contacts", $objController->url()->fromRoute("front-comms-admin/journeys") => "My Journeys", $objController->url()->fromRoute("front-form-admin") => "My Forms", $objController->url()->fromRoute("front-users") => "Manage Users"); //check if panels is enabled for profile if (in_array("panels", $objUser->profile->plugins_enabled)) { $arr_locations[$objController->url()->fromRoute("front-panels-display")] = "My Panels"; } //end if $objForm->get("home_page")->setValueOptions($arr_locations); //set news feed options $arr_config = $this->getServiceLocator()->get("config")["profile_config"]; if (!isset($arr_config["news_feed_credentials"])) { $objForm->remove("news_feed_options"); } //end if //set contact toolkit default tab options $arr_contact_toolkit_default_tab = array("comments" => "Comments", "forms" => "Forms", "journeys" => "Journeys", "status-history" => "Status History"); //add some more items to the contact toolkit default tabs list if (in_array("to_do_list", $objUser->profile->plugins_enabled)) { $arr_contact_toolkit_default_tab["user-tasks"] = "To-Do List"; } //end if if (in_array("sales_funnels", $objUser->profile->plugins_enabled)) { $arr_contact_toolkit_default_tab["sales-funnels"] = "Trackers"; } //end if // $objForm->get("contacts_toolkit_default_tab")->setValueOptions($arr_contact_toolkit_default_tab); return $objForm; }
/** * Password confirm request */ public function pcAction() { $objUser = FrontUserSession::isLoggedIn(); if ($objUser !== FALSE) { return $this->redirect()->toRoute("home"); } //end if //check if code has been set $i = $this->params()->fromQuery('i', ''); if ($i == '') { return array('errorText' => 'Required information to complete the request is not available.'); } //end if $request = $this->getRequest(); if ($request->isPost()) { $arr_data = (array) $request->getPost(); if ($arr_data['password'] != $arr_data['password_confirm']) { return array('noticeText' => 'Password does not match, please try again'); } //end if $arr_data['code'] = $i; try { $objUser = $this->getUserLoginModel()->passwordResetConfirm($arr_data); $this->flashMessenger()->addInfoMessage('Your request has been processed'); return $this->redirect()->toRoute("home"); } catch (\Exception $e) { $text = $this->frontControllerErrorHelper()->formatErrors($e); return array('noticeText' => $text); } //end catch } //end if return array(); }
/** * Load toolkit sections available * @return \Zend\View\Model\JsonModel */ public function iframeContactToolkitSectionsAction() { //set layout to toolkit $this->layout('layout/toolkit-parent'); $contact_id = $this->params()->fromRoute("id", ""); //load contact $objContact = $this->getContactsModel()->fetchContact($contact_id); $arr = array("comments" => array("title" => "Comments", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-comments", "id" => $contact_id))), "forms" => array("title" => "Forms Completed", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-forms-completed", "id" => $contact_id))), "journeys" => array("title" => "Journeys", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-journeys", "id" => $contact_id))), "status-history" => array("title" => "Contact Status", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-status-history", "id" => $contact_id))), "user-tasks" => array("title" => "To-do", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-user-tasks", "id" => $contact_id))), "sales-funnels" => array("title" => "Trackers", "url" => $this->url()->fromRoute("front-contact-toolkit", array("action" => "contact-sales-funnels", "id" => $contact_id)))); //check plugins enabled $objUser = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); if (!in_array("to_do_list", $objUser->profile->plugins_enabled)) { unset($arr["user-tasks"]); } //end if if (!in_array("sales_funnels", $objUser->profile->plugins_enabled)) { unset($arr["sales-funnels"]); } //end if return array("arr_sections" => $arr, "objContact" => $objContact); }
/** * Initiate an HTTP GET request * This is used to request a list of data. * Where get params are specified, it normally returns data for a specific entity * @param array $arr_request_params - optional * @return Ambigous <\FrontCore\Models\ApiRequestModel, \FrontCore\Models\ApiRequestModel> */ public function performGETRequest($arr_request_params = NULL) { if (is_object($arr_request_params) && $arr_request_params instanceof \Zend\Stdlib\ArrayObject) { $arr_request_params = $arr_request_params->getArrayCopy(); } //end if //load user session data $objUserSession = FrontUserSession::isLoggedIn(); //configure the request and client $request = new Request(); $request->setUri(self::buildURI()); $request->setMethod(Request::METHOD_GET); $client = new Client(); $client->setRequest($request); //set GET params if any if (is_array($arr_request_params)) { $client->setParameterGet($arr_request_params); } //end if //execute return self::executeRequest($client, $request); }
/** * Check if a user is logged in * If not, setup a session with the correct key for form submission to work * @param int $form_id * @return stdClass */ private function setUserLogin($form_id) { //check if user is logged into frontend $objUserSession = FrontUserSession::isLoggedIn(); if (!$objUserSession) { //create the request object $objApiRequest = $this->getApiRequestModel(); //disable api session login $objApiRequest->setAPISessionLoginDisable(); //load master user details $arr_user = $this->getServiceLocator()->get("config")["master_user_account"]; //set api request authentication details $objApiRequest->setAPIKey($arr_user['apikey']); $objApiRequest->setAPIUser(md5($arr_user['uname'])); $objApiRequest->setAPIUserPword(md5($arr_user['pword'])); return (object) array("form_id" => $form_id, "api_key" => $arr_user["apikey"]); } //end function }
private function renderOutputFormat($layout = "layout/layout-toolkit-body") { $this->layout($layout); $objUserSession = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); $this->objUserSession = $objUserSession; }
/** * Submit a webform * @return Ambigous <\Zend\Http\Response, \Zend\Stdlib\ResponseInterface>|Ambigous <unknown, \Zend\Form\Form> */ public function bfAction() { //set container for additional params $arr_additional_params = array(); $form_id = $this->params()->fromRoute("fid"); $reg_id = $this->params()->fromRoute("reg_id", NULL); $arr_additional_params["reg_id"] = $reg_id; //check if reg id is encoded, if not, do not process if (is_numeric($reg_id)) { $this->flashMessenger()->addErrorMessage("An error occured attempting to load data"); //redirect back to form return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id)); } //end if //load comm history id $comm_history_id = $this->params()->fromQuery("cid", ""); if ($comm_history_id != "") { $arr_additional_params["cid"] = $comm_history_id; } //end if //check form id has been set if (!is_string($form_id)) { echo "Form could not be loaded. Required information is not available."; exit; } //end if try { //load form details $arr_return = $this->getExternalFormsModel()->loadForm($form_id, $reg_id, $arr_additional_params); $arr_return["additional_data"] = $arr_additional_params; //add plain form url $arr_return["form_url"] = $this->url()->fromRoute("majestic-external-forms/bf", array("fid" => $form_id)); } catch (\Exception $e) { //@TODO do something with the error // var_dump($e->getMessage() . " : " . $e->getPrevious()); exit; die("The requested form could not be loaded. Response: " . $this->frontControllerErrorHelper()->formatErrors($e)); } //end catch if ($arr_return["objFormRawData"]->secure_form == "1") { if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != "on" && $_SERVER["HTTPS"] != 1 && $_SERVER["SERVER_PORT"] != "443") { header("location:https://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]); } //end if } //end if //should the user be logged in? if ($arr_return["objFormRawData"]->user_login == 1) { $objUserSession = FrontUserSession::isLoggedIn(); if (!$objUserSession) { $this->flashMessenger()->addInfoMessage("User must be logged in in order to access form"); //redirect to login screen return $this->redirect()->toRoute("front-user-login"); } //end if } //end if //should the contact be specified if ($arr_return["objFormRawData"]->id_required == 1 && $reg_id == "") { echo "Form could not be loaded. Contact ID is not set"; exit; } //end if //should the form be redirected on loading? if ($arr_return["objFormRawData"]->redirect_on_load != "") { header("location:" . $arr_return["objFormRawData"]->redirect_on_load); exit; } //end if //extract form from result $form = $arr_return["objForm"]; //does form have password access enabled? //@TODO set proper session data if ($arr_return["objFormRawData"]->form_password != "" && $_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) { $form = new \Zend\Form\Form(); $form->add(array("type" => "password", "name" => "password", "attributes" => array("id" => "password", "required" => "required"), "options" => array("label" => "Form Password"))); $form->add(array("type" => "submit", "name" => "submit", "attributes" => array("value" => "Submit"))); $request = $this->getRequest(); if ($request->isPost()) { if ($request->getPost("password") == $arr_return["objFormRawData"]->form_password) { $_SESSION["form_data"]["password"] = $request->getPost("password"); return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id, "reg_id" => $reg_id)); } //end if } //end if if ($_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) { $arr_return["form"] = $form; return $arr_return; } //end if } //end if //is form captcha enabled? if ($arr_return["objFormRawData"]->captcha == 1) { if (!is_dir("./public/captcha")) { mkdir("./public/captcha", 0755, TRUE); } //end if $objCaptcha = new \Zend\Captcha\Image(array('expiration' => '300', 'wordlen' => '7', 'font' => 'data/fonts/arial.ttf', 'fontSize' => '20', 'imgDir' => 'public/captcha', 'imgUrl' => '/captcha', 'lineNoiseLevel' => 1, 'dotNoiseLevel' => 1)); $form->add(array("name" => "captcha", "type" => "Zend\\Form\\Element\\Captcha", "attributes" => array("id" => "captcha", "required" => "required", "autocomplete" => "off"), "options" => array("label" => "Human verification", "captcha" => $objCaptcha))); } //end if $arr_return["form_posted"] = FALSE; $request = $this->getRequest(); if ($request->isPost()) { if ($form->has("captcha")) { if (!$objCaptcha->isValid($request->getPost("captcha"), $request->getPost())) { $form->setData($request->getPost()); $this->flashMessenger()->addErrorMessage("CAPTCHA validation failed"); $arr_return["form"] = $form; return $arr_return; } //end if } //end if //set form post flag to stop javascript loading on form error $arr_return["form_posted"] = TRUE; $form->setData($request->getPost()); if ($form->isValid($request->getPost())) { try { //submit the form $objResult = $this->getExternalFormsModel()->processFormSubmit($form_id, $form->getData(), $arr_additional_params); //unset form password if (isset($_SESSION["form_data"]["password"])) { unset($_SESSION["form_data"]["password"]); } //end if //redirect to post submit page return $this->redirect()->toRoute("majestic-external-forms/bfs", array("fid" => $form_id, "reg_id" => $objResult->data->reg_id_encoded)); } catch (\Exception $e) { //extract errors from the request return by the API $arr_response = explode("||", $e->getMessage()); $objResponse = json_decode($arr_response[1]); //check if user is logged in to display links to duplicate contacts $objUserSession = FrontUserSession::isLoggedIn(); if (is_object($objResponse) && is_object($objUserSession)) { switch ($objResponse->HTTP_RESPONSE_CODE) { case 409: //duplicates found //extract message $arr_t = explode(":", $objResponse->HTTP_RESPONSE_MESSAGE); $id_string = array_pop($arr_t); $this->flashMessenger()->addErrorMessage(trim(str_replace(array("{", "}"), "", $id_string))); //extract ids and create links to each preg_match('~{(.*?)}~', $id_string, $output); $arr_contact_ids = explode(",", $output[1]); if (is_array($arr_contact_ids) && count($arr_contact_ids) > 0) { foreach ($arr_contact_ids as $k => $id) { $this->flashMessenger()->addInfoMessage("<a href=\"" . $this->url()->fromRoute("front-contacts", array("action" => "view-contact", "id" => $id)) . "\" target=\"_blank\" title=\"View Contact\">Click to view duplicate {$id}</a>"); if ($k > 19) { break; } //end if } //end foreach } //end if break; default: //add errors to the form already where set //@TODO this needs some work, messages should be generated back into the form directly... if (is_object($objResponse) && isset($objResponse->data)) { foreach ($objResponse->data as $k => $objField) { if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) { if ($form->has($objField->attributes->name)) { $arr_message = (array) $objField->messages; $form->get($objField->attributes->name)->setMessages($arr_message); $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name)); } //end if } //end if } //end if } //end if //set form errors $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage()); break; } //end switch } else { //@TODO this needs some work, messages should be generated back into the form directly... if (is_object($objResponse) && isset($objResponse->data)) { foreach ($objResponse->data as $k => $objField) { if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) { if ($form->has($objField->attributes->name)) { $arr_message = (array) $objField->messages; $form->get($objField->attributes->name)->setMessages($arr_message); $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name)); } //end if } //end if } //end if } //end if //set form errors $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage()); } //end if } //end catch } //end if } //end if $arr_return["form"] = $form; $arr_return["form_id"] = $form_id; if ($reg_id != "") { $arr_return["reg_id"] = $reg_id; } //end if return $arr_return; }
/** * Update an existing User * @return multitype:\Zend\Form\Form */ public function editAction() { // Get ID from route $id = $this->params()->fromRoute("id", ""); if ($id == "") { // Set unsuccessful message $this->flashMessenger()->addErrorMessage("User could not be loaded. ID is not set."); // Redirect to index page return $this->redirect()->toRoute("front-users"); } //end if // Load existing User details $objUser = $this->getUsersModel()->fetchUser($id); // Load form of user $form = $this->getUsersModel()->getUserSystemForm(); //remove required attribute from password field $form->get("pword")->setAttribute("required", FALSE); $objUser->set("pword", ""); // Populate specific User.ID $form->bind($objUser); // Loads HTTP request. $request = $this->getRequest(); if ($request->isPost()) { // Load data into form of User $form->setData($request->getPost()); if ($request->getPost("pword") == "") { $form->remove("pword"); } //end if if ($form->isValid()) { try { $objUser = $form->getData(); $objUser->set("id", $id); if ($request->getPost("pword") == "") { $objUser->set("pword", ""); } //end if $objUser = $this->getUsersModel()->updateUser($objUser); // Set successful message $this->flashMessenger()->addSuccessMessage("User details have been saved"); //check if logged in user updated its own details $objUserSession = FrontUserSession::isLoggedIn(); if ($objUserSession->id == $objUser->get("id") && $request->getPost("pword") != "") { //log user out $this->flashMessenger()->addInfoMessage("Password change has been detected. Please login to continue"); return $this->redirect()->toRoute("front-user-login", array("action" => "logout")); } //end if // Redirect to index page return $this->redirect()->toRoute("front-users"); } catch (\Exception $e) { //set error message $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage()); } //end try{} } //end if } // end if // Load form of User return array("form" => $form, "objUser" => $objUser); }
/** * @param ServiceLocatorInterface $serviceLocator * @return \Zend\Navigation\Navigation */ public function createService(ServiceLocatorInterface $serviceLocator) { if (!FrontUserSession::isLoggedIn()) { return new Navigation(array()); } //end if //load the user session $objUserSession = new Container("user"); //load route map $arr_route_map = $serviceLocator->get("config")["api_route_vs_front_route_map"]; //container for routes allowed for logged in user $arr_user_navigation = array(); if (is_array($objUserSession->arr_user_acl)) { $arr_user_navigation = $objUserSession->arr_user_acl; } else { //check mode of acl engine switch (strtolower($objUserSession->acl->profile_acl_mode)) { case "strict": case "relaxed": default: $arr_t = (array) $objUserSession->acl->user_acl_access_allowed; foreach ($arr_route_map as $route => $arr_acl_resources) { foreach ($arr_acl_resources as $resource) { if ((isset($arr_t[$resource]) || in_array($resource, (array) $objUserSession->acl->user_acl_access_allowed)) && !in_array($route, $arr_user_navigation)) { $arr_user_navigation[] = $route; } //end if } //end foreach } //end foreach break; } //end switch //save user acl to session $objUserSession->arr_user_acl = $arr_user_navigation; } //end if //load navigation $arr_pages = $this->getPages($serviceLocator); foreach ($arr_pages as $key => $arr_page) { //get route match from map if (in_array(strtolower($arr_page["route"]), $this->arr_ignore_route_map)) { //check second level nav if (isset($arr_page["pages"]) && is_array($arr_page["pages"])) { foreach ($arr_page["pages"] as $kk => $arr_rr) { if (in_array($arr_rr["route"], $this->arr_ignore_route_map)) { continue; } //end if if (!in_array($arr_rr["route"], $arr_user_navigation)) { // unset($arr_pages[$key][$kk]); } else { //check third level nav if (isset($arr_rr["pages"]) && is_array($arr_rr["pages"])) { foreach ($arr_rr["pages"] as $kkk => $arr_rrr) { if (in_array($arr_rrr["route"], $this->arr_ignore_route_map)) { continue; } //end if if (!in_array($arr_rrr["route"], $arr_user_navigation)) { // unset($arr_pages[$key][$kk][$kkk]); } //end if } //end foreach } //end if } //end if } //end foreach } //end foreach continue; } else { if (!in_array($arr_page["route"], $arr_user_navigation)) { // unset($arr_pages[$key]); } //end if } //end if } //end foreach //sort pages into required groups $arr_menu = array("relationship" => array("label" => "Relationships", "route" => "home"), "data" => array("label" => "Data", "route" => "home"), "sales" => array("label" => "Sales", "route" => "home"), "profile-management" => array("label" => "Profile", "route" => "home")); if (!is_array($arr_pages)) { $arr_pages = array(); } //end if foreach ($arr_pages as $key => $arr_page) { switch ($arr_page["route"]) { /** * Relationships */ case "front-comms-admin/journeys": case "front-contacts": $arr_menu["relationship"]["pages"][] = $arr_page; break; /** * Data */ /** * Data */ case "front-custom-tables": case "front-statuses": $arr_menu["data"]["pages"][] = $arr_page; break; /** * Sales */ /** * Profile Management */ /** * Sales */ /** * Profile Management */ case "front-users": $arr_menu["profile-management"]["pages"][] = $arr_page; break; /** * Ignore */ /** * Ignore */ case "home": case "front-inbox-manager": case "front-power-tools/announcements": //do nothing break; default: break; } //end switch } //end foreach return new Navigation($arr_pages); }
/** * Check if behaviours are active against profile plugin settings * @throws \Exception */ private function isBehavioursActive() { //load session for plugins enabled $objUserSession = \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); if (!isset($objUserSession->plugins_enabled)) { //plugins not managed return; } //end if $arr_plugins = (array) $objUserSession->plugins_enabled; if (!in_array("behviours_basic", $arr_plugins) && !in_array("behaviours_advanced", $arr_plugins)) { throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : Behaviours are not activated", 500); } //end if }
/** * Set path to config file */ private function setPath($include_file = TRUE) { $objUser = FrontUserSession::isLoggedIn(); if (!$objUser) { return FALSE; header("location:/user/login"); //@TODO this redirect breaks external entities, is the return causing security gaps? exit; } //end if //set cache $this->objCache = $this->getServiceLocator()->get("FrontCore\\Caches\\FrontCachesRedis"); //retrieve profile identifier $profile_id = $objUser->profile->profile_identifier; //check if path exists if (!is_dir("./data/profiles/settings/{$profile_id}")) { mkdir("./data/profiles/settings/{$profile_id}", 0755, TRUE); } //end if if ($include_file === TRUE) { $this->path = "./data/profiles/settings/{$profile_id}/" . $profile_id . ".dat"; if (!is_file($this->path)) { file_put_contents($this->path, json_encode(array(), JSON_FORCE_OBJECT)); } //end if } else { $this->path = "./data/profiles/settings/{$profile_id}"; } //end if }
private function getUserSession() { return \FrontUserLogin\Models\FrontUserSession::isLoggedIn(); }
public function userSettingsAction() { //check if user is already logged in, if so, redirect to the home page $objUser = FrontUserSession::isLoggedIn(); if ($objUser === FALSE) { return $this->redirect()->toRoute("home"); } //end if //set layout $this->layout("layout/layout"); //create form $objForm = new Form(); $objForm->add(array("type" => "text", "name" => "locale_timezone", "attributes" => array("id" => "locale_timezone", "disabled" => "disabled", "title" => "Timezone currently set for your profile"), "options" => array("label" => "Timezone"))); //populate form values using user settings foreach ($objForm as $objElement) { $objForm->get($objElement->getName())->setValue($objUser->user_settings->{$objElement->getName()}); } //end foreach return array("objUser" => $objUser, "form" => $objForm); }
public function readMessages($initial = FALSE) { $arr_config = $this->getServiceLocator()->get("config")["profile_config"]; //load user session $objUser = FrontUserSession::isLoggedIn(); if (!isset($arr_config["news_feed_credentials"]) || !isset($objUser->profile->plugins->newsfeed_exchange)) { //return emtpy object for javascript return (object) array(json_encode(array("id" => ""))); } //end if if ($initial === TRUE) { if (isset($_SESSION["user_news_feed"])) { $this->arr_messages = $_SESSION["user_news_feed"]; if (count($this->arr_messages) > 2) { return array_reverse($this->arr_messages); } //end if } else { $this->arr_messages[] = json_encode((object) array("id" => "")); } //end if } //end if $this->objChannel = $this->getConnectionChannel($arr_config["news_feed_credentials"]); $exchange = $objUser->profile->plugins->newsfeed_exchange; $consumer_tag = 'consumer' . getmypid(); //set queue identifier if (!isset($objUser->user_news_feed_queue) || $objUser->user_news_feed_queue == "") { $objUser->user_news_feed_queue = sha1(md5(microtime(TRUE) . rand(time(), 249348748) . $consumer_tag)); $queue = $objUser->user_news_feed_queue; } else { $queue = $objUser->user_news_feed_queue; } //end if /* name: $queue // should be unique in fanout exchange. passive: false // don't check if a queue with the same name exists durable: false // the queue will not survive server restarts exclusive: false // the queue might be accessed by other channels auto_delete: true //the queue will be deleted once the channel is closed. */ $this->objChannel->queue_declare($queue, false, false, false, true, new AMQPTable(array("x-message-ttl" => 60 * 5 * 100))); $this->objChannel->queue_bind($queue, $exchange); for ($i = 0; $i < 30; $i++) { $msg = $this->objChannel->basic_get($queue); if (is_object($msg)) { array_unshift($this->arr_messages, $msg->body); $this->objChannel->basic_ack($msg->delivery_info['delivery_tag']); } //end if } //end for //save to session if (count($this->arr_messages) > 0 && $initial !== TRUE) { if (!isset($_SESSION["user_news_feed"]) || !is_array($_SESSION["user_news_feed"])) { $_SESSION["user_news_feed"] = array(); $arr_messages = array(); } else { $arr_messages = $_SESSION["user_news_feed"]; } //end if $arr_total = array_merge($this->arr_messages, $arr_messages); if (count($arr_total) > 50) { $_SESSION["user_news_feed"] = $this->arr_messages = array_slice($arr_total, 0, 50); } else { $_SESSION["user_news_feed"] = $arr_total; } //end if } //end if if (count($this->arr_messages) == 0 && $initial !== TRUE && isset($_SESSION["user_news_feed"]) && count($_SESSION["user_news_feed"]) > 0) { $this->arr_messages = array_reverse($_SESSION["user_news_feed"]); } //end if //close connection $this->close(); //reverse the order, the information is prended in view return $this->arr_messages; }