Example #1
0
 public function listClientsAction()
 {
     // web page title
     $this->view->title = "Clients";
     if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) {
         $profile = new GenericProfile();
         $member = new MemberProfile();
         $oRetailer = new RetailersObject();
         $selectRetailer = $oRetailer->getAll(null, false);
         $selectRetailer->joinRight($profile->getGenericTable(), 'R_GenericProfileId = GP_MemberID', array('lastName' => 'GP_LastName', 'firstName' => 'GP_FirstName', 'email' => 'GP_Email'));
         $select = $selectRetailer->joinRight($member->getTable(), 'GP_MemberID = MP_GenericProfileMemberID', array('member_id' => 'MP_GenericProfileMemberID', 'company' => 'MP_CompanyName', 'MP_Status' => 'MP_Status'));
         $tables = array('GenericProfiles' => array('GP_LastName', 'GP_FirstName', 'GP_Email'), 'RetailersData' => array('R_ID', 'R_GenericProfileID', 'R_AddressId', 'R_Status'));
         $field_list = array('company' => array('width' => '250px'), 'lastName' => array('width' => '250px'), 'firstName' => array('width' => '250px'));
         $tables = array('GenericProfiles' => array('GP_lastName', 'GP_firstName'), 'MemberProfiles' => array('MP_CompanyName'));
         $this->view->params = $this->_getAllParams();
         $pageID = $this->_getParam('pageID');
         $langId = $this->_registry->languageID;
         $options = array('commands' => array($this->view->link($this->view->url(array('module' => 'profile', 'controller' => 'index', 'action' => 'add', 'returnModule' => $this->_moduleTitle, 'returnAction' => 'list-clients')), $this->view->getCibleText('button_add_profile'), array('class' => 'action_submit add'))), 'excludedColums' => array('Nom'), 'disable-export-to-excel' => '', 'to-excel-action' => 'clients-to-excel', 'filters' => array('filter_1' => array('label' => 'Liste des détaillants', 'default_value' => null, 'associatedTo' => 'GP_MemberID', 'equalTo' => 'R_GenericProfileId', 'choices' => array('' => 'Liste des détaillants', '1' => "--> Affichés sur le site")), 'filter_2' => array('label' => 'Liste des détaillants', 'default_value' => null, 'associatedTo' => 'MP_Status', 'choices' => array('' => 'Filtrer par statut', '-1' => 'Désactivé', '0' => 'Email non validé', '1' => 'À valider', '2' => 'Activé'))), 'action_panel' => array('width' => '50', 'actions' => array('edit' => array('label' => $this->view->getCibleText('menu_submenu_action_edit'), 'url' => $this->view->url(array('module' => 'profile', 'action' => 'edit', 'ID' => "-ID-", 'returnModule' => $this->_moduleTitle, 'returnAction' => 'list-clients')), 'findReplace' => array('search' => '-ID-', 'replace' => 'member_id')), 'delete' => array('label' => $this->view->getCibleText('menu_submenu_action_delete'), 'url' => $this->view->url(array('module' => 'profile', 'action' => 'delete', 'ID' => "-ID-", 'returnModule' => $this->_moduleTitle, 'returnAction' => 'list-clients')), 'findReplace' => array('search' => '-ID-', 'replace' => 'member_id')))));
         $mylist = new Cible_Paginator($select, $tables, $field_list, $options);
         $this->view->assign('mylist', $mylist);
     }
 }
Example #2
0
 public function ajaxRetailersAction()
 {
     if ($this->_isXmlHttpRequest) {
         $this->getHelper('viewRenderer')->setNoRender();
         $this->disableLayout();
         $this->disableView();
         $langId = $this->_getParam('langId');
         $retailerId = $this->_getParam('retailerId');
         $field = $this->_getParam('field');
         $oRetailers = new RetailersObject();
         $params = array('field' => $field, 'value' => $this->_getParam('value'));
         if ($retailerId) {
             $retailersData = $oRetailers->getRetailersDataByCities($params, $retailerId, $langId);
         } else {
             $retailersData = $oRetailers->getRetailersDataByCities($params, null, $langId);
         }
         if ($this->_getParam('render') != 'false') {
             $retailers = $this->renderRetailers($retailersData);
         } else {
             foreach ($retailersData as $data) {
                 foreach ($data as $key => $value) {
                     $data[$key] = $value;
                 }
                 $dataForJson[] = $data;
             }
             $retailers = $dataForJson;
         }
         echo json_encode($retailers);
     }
 }
Example #3
0
 /**
  * Allocates action for retailers data management.<br />
  * Prepares data utilized to activate controller actions.
  *
  * @access public
  *
  * @return void
  */
 public function retailersAction($getParams = false)
 {
     if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) {
         //            $this->_disableExportToExcel = true;
         $this->_constraint = '';
         $this->_colTitle = array('R_GenericProfileId' => array('width' => '150px'), 'R_Status' => array('width' => '150px'));
         $this->_joinTables = array('GenericProfile');
         if ($getParams) {
             $params = array('columns' => $this->_colTitle, 'joinTables' => $this->_joinTables, 'formName' => 'FormRetailersProfile');
             return $params;
         }
         $this->_formName = 'FormRetailersProfile';
         if ($this->_isXmlHttpRequest && $this->_request->isPost()) {
             $_POST['R_GenericProfileId'] = $this->_genericId;
             if ($this->_actionKey == 'delete') {
                 $oRetailer = new RetailersObject();
                 $data = $oRetailer->getRetailerInfos($this->_genericId);
                 $this->_genericId = $data['R_RetailerProfileId'];
             }
         }
         $this->_redirectAction();
     }
 }
Example #4
0
 /**
  * Create a new account or edit an existing one.
  *
  * @return void
  */
 public function becomeclientAction()
 {
     // Test if the user is already connected.
     $account = Cible_FunctionsGeneral::getAuthentication();
     // Set the default status to an account creation and not editing one
     $_edit = false;
     // Instantiate the user profiles
     $profile = new MemberProfile();
     $newsletterProfile = new NewsletterProfile();
     $memberData = array();
     $accountValidate = true;
     //Set Default id for states and cities
     $config = Zend_Registry::get('config');
     $current_state = $config->address->default->states;
     $currentCity = '';
     $notifyAdmin = array();
     // Get users data if he is already logged
     if ($account) {
         if ($account['status'] == 2 || $this->_request->isPost()) {
             $_edit = true;
             $memberData = $profile->findMember(array('email' => $account['email']));
             $newsletterData = $newsletterProfile->findMember(array('email' => $account['email']));
             $oAddress = new AddressObject();
             if (!empty($memberData['addrBill'])) {
                 $billAddr = $oAddress->populate($memberData['addrBill'], $this->_defaultInterfaceLanguage);
             }
             if (!empty($memberData['addrShip'])) {
                 $shipAddr = $oAddress->populate($memberData['addrShip'], $this->_defaultInterfaceLanguage);
             }
             $oRetailer = new RetailersObject();
             $onWeb = $oRetailer->getRetailerInfos($memberData['member_id'], $this->_defaultInterfaceLanguage);
             $memberData['AI_FirstTel'] = $billAddr['AI_FirstTel'];
             $memberData['AI_SecondTel'] = $billAddr['AI_SecondTel'];
             $memberData['A_Fax'] = $billAddr['A_Fax'];
             if (isset($billAddr['AI_WebSite'])) {
                 $memberData['AI_WebSite'] = $billAddr['AI_WebSite'];
             }
             $memberData['addressFact'] = $billAddr;
             if (!$shipAddr['A_Duplicate']) {
                 $shipAddr['duplicate'] = 0;
             }
             $memberData['addressShipping'] = $shipAddr;
             $current_state = $billAddr['A_StateId'] . self::SEPARATOR . $shipAddr['A_StateId'] . self::SEPARATOR;
             $currentCity = $billAddr['A_CityId'] . self::SEPARATOR . $shipAddr['A_CityId'] . self::SEPARATOR;
             if ($onWeb && !empty($onWeb['R_AddressId'])) {
                 $webAddr = $oAddress->populate($onWeb['R_AddressId'], $this->_defaultInterfaceLanguage);
                 $webAddr['isDistributeur'] = $onWeb['R_Status'];
                 $memberData['addressDetaillant'] = $webAddr;
                 $current_state .= $webAddr['A_StateId'] . '||';
                 $currentCity .= $webAddr['A_CityId'] . '||';
             }
             //            if (empty($this->view->step))
             $this->view->headTitle($this->view->getClientText('account_modify_page_title'));
         }
     }
     $this->view->assign('accountValidate', $accountValidate);
     $options = $_edit ? array('mode' => 'edit') : array();
     $_edit ? $this->view->assign('mode', 'edit') : $this->view->assign('mode', 'add');
     // Instantiate the form for account management
     $form = new FormBecomeClient($options);
     //$_captcha = $form->getElement('captcha');
     $countries = Cible_FunctionsGeneral::getCountries();
     $addressFields = array();
     $return = $this->_getParam('return');
     if ($return && isset($_COOKIE['returnUrl'])) {
         $returnUrl = $_COOKIE['returnUrl'];
         $this->view->assign('return', $returnUrl);
     }
     $this->view->assign('selectedCity', $currentCity);
     $this->view->assign('selectedState', $current_state);
     $addressFields = array_unique($addressFields);
     // Test if the users has ticked the aggreement checkbox
     $agreementError = isset($_POST['termsAgreement']) && $_POST['termsAgreement'] != 1 ? true : false;
     if ($_edit) {
         $agreementError = false;
     }
     $this->view->assign('agreementError', $agreementError);
     // Actions when form is submitted
     if ($this->_request->isPost() && array_key_exists('submit', $_POST)) {
         $formData = $this->_request->getPost();
         // Test if the email already exists and password is the same
         if ($_edit) {
             $subFormI = $form->getSubForm('identification');
             if ($formData['identification']['email'] != $memberData['email']) {
                 $findEmail = $profile->findMember(array('email' => $formData['identification']['email']));
                 if ($findEmail) {
                     $emailNotFoundInDBValidator = new Zend_Validate_Db_NoRecordExists('GenericProfiles', 'GP_Email');
                     $emailNotFoundInDBValidator->setMessage($this->view->getClientText('validation_message_email_already_exists'), 'recordFound');
                     $subFormI->getElement('email')->addValidator($emailNotFoundInDBValidator);
                 }
             }
             if (empty($formData['identification']['password']) && empty($formData['identification']['passwordConfirmation'])) {
                 $subFormI->getElement('password')->clearValidators()->setRequired(false);
                 $subFormI->getElement('passwordConfirmation')->clearValidators()->setRequired(false);
             }
         }
         $oAddress = new AddressObject();
         // Get the addresses data to insert
         $addressFact = $formData['addressFact'];
         $addressShipping = $formData['addressShipping'];
         //            $addressRetailer = $formData['addressDetaillant'];
         //Remove data form form if the shipping address is the same as bill
         if ($addressShipping['duplicate'] == 1) {
             $subFormShip = $form->getSubForm('addressShipping');
             foreach ($subFormShip as $key => $value) {
                 $value->clearValidators()->setRequired(false);
             }
             unset($formData['addressShipping']);
         }
         //If customer doesn't want to add data on website, set to false the field name
         //            if ($addressRetailer['isDistributeur'] == 1)
         //                $form->getSubForm('addressDetaillant')->getElement('AI_Name')->clearValidators()->setRequired(false);
         if ($form->isValid($formData) && !$agreementError) {
             //remove addresses
             unset($formData['addressFact'], $formData['addressShipping'], $formData['addressDetaillant']);
             // merge all subform fields for the member profile table
             $formData = $this->_mergeFormData($formData);
             //get the last data to merge in the billing address
             //                $addressFact['A_Fax']        = $formData['A_Fax'];
             //                $addressFact['AI_FirstTel']  = $formData['AI_FirstTel'];
             //                $addressFact['AI_SecondTel'] = $formData['AI_SecondTel'];
             //                $addressFact['AI_WebSite']   = $formData['AI_WebSite'];
             if (!empty($formData['password'])) {
                 $password = $formData['password'];
                 $formData['password'] = md5($password);
             }
             if (!$_edit) {
                 // Do the processing here
                 $validatedEmail = Cible_FunctionsGeneral::generatePassword();
                 $path = Zend_Registry::get('web_root') . '/';
                 $hash = md5(session_id());
                 $duration = 0;
                 $cookie = array('lastName' => utf8_encode($formData['lastName']), 'firstName' => utf8_encode($formData['firstName']), 'email' => $formData['email'], 'hash' => $hash, 'status' => 0);
                 $formData['hash'] = $hash;
                 $formData['validatedEmail'] = $validatedEmail;
                 /// $this->save($memberId, $data);
                 //Add addresses process and retrive id for memberProfiles
                 $idBillingAddr = $oAddress->insert($addressFact, $this->_defaultInterfaceLanguage);
                 if ($addressShipping['duplicate'] == 1) {
                     $addressFact['A_Duplicate'] = $idBillingAddr;
                     $idShippingAddr = $oAddress->insert($addressFact, $this->_defaultInterfaceLanguage);
                 } else {
                     $idShippingAddr = $oAddress->insert($addressShipping, $this->_defaultInterfaceLanguage);
                 }
                 $formData['addrBill'] = $idBillingAddr;
                 $formData['addrShip'] = $idShippingAddr;
                 $profile->addMember($formData);
                 $memberData = $profile->findMember(array('email' => $formData['email']));
                 $idMember = $memberData['member_id'];
                 //                    if ($addressRetailer['isDistributeur'] == 2)
                 //                    {
                 //                        $oRetailer = new RetailersObject();
                 //                        $idRetailerAddr = $oAddress->insert($addressRetailer, $this->_defaultInterfaceLanguage);
                 //
                 //                        $retailerData = array(
                 //                            'R_GenericProfileId' => $idMember,
                 //                            'R_AddressId' => $idRetailAddr,
                 //                            'R_Status' => $addressRetailer['isDistributeur']
                 //                        );
                 //
                 //                        $oRetailer->insert($retailerData, $this->_defaultInterfaceLanguage);
                 //                    }
                 setcookie("authentication", json_encode($cookie), $duration, $path);
                 $data = array('firstName' => $memberData['firstName'], 'lastName' => $memberData['lastName'], 'email' => $memberData['email'], 'language' => $formData['language'], 'validatedEmail' => $formData['validatedEmail'], 'password' => $password);
                 $options = array('send' => true, 'isHtml' => true, 'to' => $formData['email'], 'moduleId' => $this->_moduleID, 'event' => 'newAccount', 'type' => 'email', 'recipient' => 'client', 'data' => $data);
                 $oNotification = new Cible_Notifications_Email($options);
                 //                    $notifyAdmin = array();
                 $this->view->assign('needConfirm', true);
                 $this->renderScript('index/confirm-email.phtml');
             } else {
                 if (empty($formData['password'])) {
                     unset($formData['password']);
                 }
                 $oAddress->save($billAddr['A_AddressId'], $addressFact, $this->_defaultInterfaceLanguage);
                 if ($addressShipping['duplicate'] == 1) {
                     $addressFact['A_Duplicate'] = $billAddr['A_AddressId'];
                     $oAddress->save($shipAddr['A_AddressId'], $addressFact, $this->_defaultInterfaceLanguage);
                 } else {
                     $addressShipping['A_Duplicate'] = 0;
                     $oAddress->save($shipAddr['A_AddressId'], $addressShipping, $this->_defaultInterfaceLanguage);
                 }
                 //                    $retailerData = array(
                 //                        'R_Status' => $addressRetailer['isDistributeur']);
                 //
                 //                    switch ($addressRetailer['isDistributeur'])
                 //                    {
                 //                        case 1:
                 //                            if (!empty($onWeb))
                 //                            {
                 //                                $retailerData = array(
                 //                                    'R_Status' => $addressRetailer['isDistributeur']);
                 //                                $oRetailer->save($onWeb['R_ID'], $retailerData, $this->_defaultInterfaceLanguage);
                 //                            }
                 //                            break;
                 //                        case 2:
                 //                            if (!empty($webAddr))
                 //                            {
                 //                                $retailerData = array(
                 //                                    'R_Status' => $addressRetailer['isDistributeur']);
                 //                    $oAddress->save($webAddr['A_AddressId'], $addressRetailer, $this->_defaultInterfaceLanguage);
                 //                    $oRetailer->save($onWeb['R_ID'], $retailerData, $this->_defaultInterfaceLanguage);
                 //                            }
                 //                            else
                 //                            {
                 //                                $addressId = $oAddress->insert($addressRetailer, $this->_defaultInterfaceLanguage);
                 //                                $retailerData = array(
                 //                                    'R_GenericProfileId' => $memberID,
                 //                                    'R_AddressId' => $addressId,
                 //                                    'R_Status' => $addressRetailer['isDistributeur']
                 //                                );
                 //                                $oRetailer->insert($retailerData, $this->_defaultInterfaceLanguage);
                 //                            }
                 //                            break;
                 //                        default:
                 //                            break;
                 //                    }
                 $profile->updateMember($memberData['member_id'], $formData);
                 if ($formData['email'] != $memberData['email']) {
                     $validatedEmail = Cible_FunctionsGeneral::generatePassword();
                     $formData['validatedEmail'] = $validatedEmail;
                     $profile->updateMember($memberData['member_id'], $formData);
                     $data = array('firstName' => $formData['firstName'], 'lastName' => $formData['lastName'], 'email' => $formData['email'], 'language' => $formData['language'], 'validatedEmail' => $formData['validatedEmail']);
                     $options = array('send' => true, 'isHtml' => true, 'to' => $formData['email'], 'moduleId' => $this->_moduleID, 'event' => 'editResend', 'type' => 'email', 'recipient' => 'client', 'data' => $data);
                     $oNotification = new Cible_Notifications_Email($options);
                     $this->view->assign('needConfirm', true);
                     $this->renderScript('index/confirm-email.phtml');
                 } else {
                     $authentication = json_decode($_COOKIE['authentication'], true);
                     $path = Zend_Registry::get('web_root') . '/';
                     $duration = 0;
                     $cookie = array('lastName' => utf8_encode($formData['lastName']), 'firstName' => utf8_encode($formData['firstName']), 'email' => $authentication['email'], 'language' => $formData['language'], 'hash' => $authentication['hash'], 'status' => 2);
                     setcookie("authentication", json_encode($cookie), $duration, $path);
                     $this->view->assign('messages', array($this->view->getCibleText('form_account_modified_message')));
                     $this->view->assign('updatedName', $formData['firstName']);
                 }
                 $data = array('identification' => $memberData, 'addressFact' => $billAddr, 'addressShipping' => $shipAddr);
                 $notifyAdmin = $this->_testDataForNotification($this->_request->getPost(), $data);
                 // Notify admin
                 if (count($notifyAdmin) > 0) {
                     $data = array('firstName' => $formData['firstName'], 'lastName' => $formData['lastName'], 'email' => $formData['email'], 'NEWID' => $memberData['member_id'], 'language' => $formData['language'], 'validatedEmail' => $formData['validatedEmail'], 'form' => $form->populate($_POST), 'notifyAdmin' => $notifyAdmin);
                     $options = array('send' => true, 'isHtml' => true, 'moduleId' => $this->_moduleID, 'event' => 'editAccount', 'type' => 'email', 'recipient' => 'admin', 'data' => $data);
                     $oNotification = new Cible_Notifications_Email($options);
                 }
                 $this->_redirect(Cible_FunctionsCategories::getPagePerCategoryView(0, 'modify_inscription', $this->_moduleID));
             }
             if (!empty($formData['newsletterSubscription'])) {
                 $newsletterCategory = $formData['newsletterSubscription'] ? $this->_config->newsletter->default->categoryID : '';
                 $newsletterProfile->updateMember($memberData['member_id'], array('newsletter_categories' => $newsletterCategory));
             }
         } else {
             $form->populate($_POST);
         }
     } else {
         if ($_edit && empty($this->view->step)) {
             if (!empty($newsletterData['newsletter_categories'])) {
                 $memberData['newsletterSubscription'] = 1;
             }
             $form->populate($memberData);
         }
     }
     $this->view->assign('form', $form);
 }