Exemple #1
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $this->user = sfGuardUserPeer::retrieveByPK($request->getParameter('id'));
     $this->forward404Unless($this->user, 'User Not Found');
     $this->statusActions = StatusActionPeer::getStatusActionsForBoard($this->user->getId());
     $this->commentBoards = CommentPeer::getCommentsForBoard($this->user->getId());
 }
Exemple #2
0
 function getSfGuardUser()
 {
     if (!$this->sf_guard_user) {
         $this->sf_guard_user = sfGuardUserPeer::retrieveByPK($this->sf_guard_user_id);
     }
     return $this->sf_guard_user;
 }
 /**
  * Bind values and save new password
  * @param  array   $values tainted values
  * @return boolean
  */
 public function bindAndSave(array $values)
 {
     $this->bind($values);
     if ($this->isValid()) {
         $user = sfGuardUserPeer::retrieveByPK($this->getOption('userid'));
         $user->setPassword($values['password']);
         $user->save();
         return true;
     } else {
         return false;
     }
 }
 public function executeConfirmation($request)
 {
     $key = $request->getParameter('key');
     if ($key) {
         $user_profile = sfGuardUserProfilePeer::retrieveByActivationKey($key);
         if ($user_profile) {
             $user = sfGuardUserPeer::retrieveByPK($user_profile->getUserId());
             $user->setIsActive(true);
             $user->save();
             $this->getUser()->setFlash('info', 'Your account has been activated.');
             $this->forward('site', 'message');
         }
     }
     $this->getUser()->setFlash('error', 'Activation link is not valid.');
     $this->forward('site', 'message');
 }
 public function executeChangeGradeItem(sfWebRequest $request)
 {
     if ($request->isXmlHttpRequest()) {
         if ($request->getParameter('idgradeunit') != '') {
             try {
                 updateGradeImte($request->getParameter('idgradeunit'), $request->getParameter('idhorario'), $request->getParameter('iddisciplina'), $request->getParameter('idprofessor'), $request->getParameter('idlocal'), $request->getParameter('idweekday'));
             } catch (Exception $e) {
             }
             $c = new Criteria();
             $c->add(GradeunitPeer::ID, intval($request->getParameter('idgradeunit')));
             $this->content = ContentPeer::doSelectOne($c);
             if ($this->content) {
                 $this->user = sfGuardUserPeer::retrieveByPK($this->content->getUserId());
             }
             return $this->content ? sfView::SUCCESS : sfView::ERROR;
         }
     }
     $this->forward404();
 }
Exemple #6
0
 public function getsfGuardUser($con = null)
 {
     if ($this->asfGuardUser === null && $this->user_id !== null) {
         include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardUserPeer.php';
         $this->asfGuardUser = sfGuardUserPeer::retrieveByPK($this->user_id, $con);
     }
     return $this->asfGuardUser;
 }
Exemple #7
0
 public function executeConfirmRegistrationText()
 {
     sfPropelApprovableBehavior::disable();
     $this->user = sfGuardUserPeer::retrieveByPK($this->getRequest()->getAttribute('user_id'));
     $this->url = $this->user->getApprovalUrl();
 }
Exemple #8
0
 public function executeJsonUpdateUserService(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $id = $request->getParameter('id');
     if (!($sf_user = sfGuardUserPeer::retrieveByPK($id))) {
         $msg_i18n = $this->getContext()->getI18N()->__(sfGuardUserPeer::_ERR_NOTFOUND_ID_, array('%id%' => $id));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     $service_id = $request->getParameter('service_id');
     //$this->forward404Unless($etva_service = EtvaServicePeer::retrieveByPk($service_id), sprintf('Object etva_service does not exist (%s).', $service_id));
     if (!EtvaServicePeer::retrieveByPk($service_id)) {
         $msg_i18n = $this->getContext()->getI18N()->__('Object etva_service does not exist (%service_id%).', array('%service_id%' => $service_id));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     $etva_user_service = EtvaUserServicePeer::retrieveByPK($id, $service_id);
     if (!$etva_user_service) {
         $etva_user_service = new EtvaUserService();
         $etva_user_service->setUserId($id);
         $etva_user_service->setServiceId($service_id);
     }
     $extra = $request->getParameter('extra');
     $etva_user_service->setExtra($extra);
     $etva_user_service->save();
     $msg_i18n = $this->getContext()->getI18N()->__('User and service saved successfully');
     $response = array('success' => true, 'agent' => 'Central Management', 'response' => $msg_i18n, 'user_id' => $id, 'service_id' => $service_id);
     $return = json_encode($response);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
 /**
  * Check if a user exists given to an id.
  * @param Int $user_id
  * @return Boolean
  */
 public static function userExists($id)
 {
     return sfGuardUserPeer::retrieveByPK($id) ? true : false;
 }
 public function executePermissions(sfWebRequest $request)
 {
     $module = 'sfGuardUser';
     if (!in_array($module, array_keys(sfPlop::getSafePluginModules()))) {
         $this->redirect('@sf_plop_dashboard');
     }
     if ($request->isMethod(sfRequest::POST)) {
         if ($request->isXmlHttpRequest()) {
             $this->setTemplate('ajaxPermissions');
             $this->setLayout(false);
         }
         $group_id = $request->getParameter('g');
         $user_id = $request->getParameter('u');
         $permission_id = $request->getParameter('p');
         if ($group_id) {
             $group_exists = sfPlopGuard::groupExists($group_id);
             if (!$group_exists && $request->isXmlHttpRequest()) {
                 return sfView::ERROR;
             } else {
                 if (!$group_exists) {
                     $this->redirect('@sf_plop_dashboard_permissions');
                 }
             }
         }
         if ($user_id) {
             $user_exists = sfPlopGuard::userExists($user_id);
             if (!$user_exists && $request->isXmlHttpRequest()) {
                 return sfView::ERROR;
             } else {
                 if (!$user_exists) {
                     $this->redirect('@sf_plop_dashboard_permissions');
                 }
             }
         }
         if (isset($group_exists) && isset($user_exists)) {
             $user_group = sfGuardUserGroupPeer::retrieveByPK($user_id, $group_id);
             if ($user_group) {
                 $user_group->delete();
             } else {
                 $user_group = new sfGuardUsergroup();
                 $user_group->setUserId($user_id);
                 $user_group->setGroupId($group_id);
                 $user_group->save();
                 $this->getResponse()->setStatusCode(201);
             }
         }
         if ($permission_id) {
             if ($permission_id == 'super') {
                 if (!sfPlopGuard::isLastSuperAdminUser($user_id)) {
                     $user = sfGuardUserPeer::retrieveByPK($user_id);
                     if ($user->getIsSuperAdmin()) {
                         $user->setIsSuperAdmin(false);
                     } else {
                         $user->setIsSuperAdmin(true);
                     }
                     $user->save();
                 } else {
                     $this->getResponse()->setStatusCode(202);
                     return sfView::ERROR;
                 }
             } else {
                 if (!is_int($permission_id)) {
                     $permission_exists = sfPlopGuard::permissionExists($permission_id);
                     if (!$permission_exists) {
                         $modules = sfPlop::getSafePluginModules();
                         if ($request->isXmlHttpRequest() && !isset($modules[$permission_id])) {
                             return sfView::ERROR;
                         } elseif (!isset($modules[$permission_id])) {
                             $this->redirect('@sf_plop_dashboard_permissions');
                         } else {
                             $module = $modules[$permission_id];
                         }
                         $permission = new sfGuardPermission();
                         $permission->setName($permission_id);
                         $permission->setDescription($module['name']);
                         $permission->save();
                         $permission_id = $permission->getId();
                         $this->getResponse()->setStatusCode(201);
                     } else {
                         $permission_id = sfPlopGuard::getPermission($permission_id)->getId();
                     }
                 } else {
                     $permission_exists = sfPlopGuard::permissionExists($permission_id);
                     if (!$permission_exists && $request->isXmlHttpRequest()) {
                         return sfView::ERROR;
                     } else {
                         if (!$permission_exists) {
                             $this->redirect('@sf_plop_dashboard_permissions');
                         }
                     }
                 }
                 if (isset($user_exists)) {
                     $user_permission = sfGuardUserPermissionPeer::retrieveByPK($user_id, $permission_id);
                     if ($user_permission) {
                         $user_permission->delete();
                     } else {
                         $user_permission = new sfGuardUserPermission();
                         $user_permission->setUserId($user_id);
                         $user_permission->setPermissionId($permission_id);
                         $user_permission->save();
                         $this->getResponse()->setStatusCode(201);
                     }
                 } elseif (isset($group_exists)) {
                     $group_permission = sfGuardGroupPermissionPeer::retrieveByPK($group_id, $permission_id);
                     if ($group_permission) {
                         $group_permission->delete();
                     } else {
                         $group_permission = new sfGuardGroupPermission();
                         $group_permission->setGroupId($group_id);
                         $group_permission->setPermissionId($permission_id);
                         $group_permission->save();
                         $this->getResponse()->setStatusCode(201);
                     }
                 }
             }
         }
         if (!$request->isXmlHttpRequest()) {
             $this->redirect('@sf_plop_dashboard_permissions');
         }
     }
     $this->groups = sfPlopGuard::getAllGroups();
     $this->users = sfPlopGuard::getAllUsers();
     $this->permissions = sfPlopGuard::getAllPermissions();
 }
Exemple #11
0
 public function addComment($comment)
 {
     // Comment *should* have author_id filled in
     // TERRIBLY f***ing hackish...no multiple inheritance...this seems to be the only way to overrride plugin behavior per-object
     $commentable = new sfPropelActAsCommentableBehavior();
     $comment['text'] = $comment['text'];
     $commentable->addComment($this, $comment);
     $author = sfGuardUserPeer::retrieveByPK($comment['author_id'])->getProfile();
     if ($author == null) {
         $name = "anonymous";
     } else {
         $name = $author->getFullName();
     }
     $this->addHistoryEvent('A new comment for project ' . $this->getTitle(), 'A new comment has been added to the project ' . $this->getTitle() . ' by ' . $name);
 }
 public function validateReset()
 {
     $this->id = $this->getUser()->getAttribute('Reset', false, 'sfApplyPlugin', false);
     if (!$this->id) {
         // No need to be polite, this is probably a hack attempt
         $this->forward404();
     }
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $password = $this->getRequestParameter('password');
         $password2 = $this->getRequestParameter('password2');
         if ($password !== $password2) {
             $this->getRequest()->setError('password', "Passwords do not match.");
             return false;
         }
         $this->sfGuardUser = sfGuardUserPeer::retrieveByPK($this->id);
         if (!$this->sfGuardUser) {
             // No need to be polite, this is probably a hack attempt
             $this->forward404();
         }
     }
     return true;
 }
 /**
  * Save client profile content
  * @param web request $request
  */
 public function executeUpdate($request)
 {
     /**login user infomation**/
     $sf_user = $this->getUser();
     $sf_guard_user = $sf_user->getGuardUser();
     $sf_user_profile = $sf_guard_user->getProfile();
     $sf_user_id = $sf_guard_user->getId();
     $branch_id = $sf_user->getUserBranch()->getId();
     $company_id = $sf_user->getUserCompany()->getId();
     $this->marketing_options = '';
     $this->cop_record_updated = '';
     $client_user_id = NULL;
     //    if($sf_ser->isBranchOwner($sf_user_id) && $sf_user->hasAttribute('branch_id'))
     if ($sf_user->isBranchOwner($sf_user_id)) {
         //        $client_user_id = $this->getRequestParameter('id');
         $client_profile_id = $this->getRequestParameter('id');
         if (!empty($client_profile_id)) {
             $client_user = ProfilePeer::retrieveByPK($client_profile_id);
             $client_user_id = $client_user->getUserId();
         }
         /*
          * available in case branch owner is handling more than branch
          * if the client is new that it need branch_id from url
          */
         if ($this->getRequestParameter('branch_id')) {
             $branch_id = $this->getRequestParameter('branch_id');
         } elseif ($client_user_id) {
             $client_branch = new Criteria();
             $client_branch->add(BranchUsersPeer::USER_ID, $client_user_id);
             $client_branch->setDistinct();
             $branchId = BranchUsersPeer::doSelect($client_branch);
             $branch_id = $branchId[0]->getBranchId();
         }
         $company_id = BranchPeer::getCompanyId($branch_id);
     }
     $parent = $request->getParameter('opportunity_parent_exist', 0);
     $this->logindetails = array();
     $this->logindetails['username'] = '';
     $this->logindetails['password'] = '';
     $this->logindetails['confirm_password'] = '';
     $this->logindetails['budget'] = '';
     $this->logindetails['expected_close_date'] = '';
     $this->getSignedContractDate = '';
     $this->another_contact_list = '';
     $this->another_contact_form = new anotherContactPersonForm();
     $this->client_leads = ClientLeadPeer::getClientLeadsList($branch_id);
     $login_details = $request->getParameter('logindetail');
     $branch_service = new BranchService($branch_id, $sf_user_id);
     $this->marketing_options = $branch_service->getMarketingOptionList();
     $this->is_showlead = $branch_service->isShowLead();
     $this->sub_opportunity_exist = null;
     if ($login_details) {
         $this->logindetails = $login_details;
         if ($this->logindetails['expected_close_date']) {
             $this->logindetails['expected_close_date'] = date('Y-m-d', strtotime($this->logindetails['expected_close_date'])) . ' ' . date('H:i:s');
         }
     }
     $this->getSignedContractDate = $this->logindetails['signed_contract_date'];
     /*
      * get current branch branch office staff list (any one of these should be the sales person)
      */
     $tempsale = array();
     $tempsale[$sf_user_id] = $sf_user->getProfile()->getFullname();
     $sales = ProfilePeer::getBranchUsers($branch_id, sfGuardGroupPeer::BRANCH_OFFICE_STAFF);
     foreach ($sales as $salesid) {
         $tempsale[$salesid->getUserId()] = $salesid->getFullname();
     }
     $this->sales_persons = $tempsale;
     $this->default_sales = $sf_user_id;
     $client_profile = '';
     $this->client_profile = '';
     $client_id = $request->getParameter('id');
     if ($client_id) {
         $client_profile = ProfilePeer::retrieveByPK($client_id);
         $client_user_id = $client_profile->getUserId();
         $this->client_ranks = clientRankPeer::getClientOpportunityList($branch_id);
         $this->default_rank = 0;
         $this->default_sub_rank = null;
         $this->default_lead = 0;
         if (!empty($client_profile)) {
             $this->default_rank = $client_profile->getRank() ? $client_profile->getRank() : 0;
             $this->default_sub_rank = $client_profile->getSubOpportunity() ? $client_profile->getSubOpportunity() : null;
         }
         $this->client_profile = $client_profile;
         if ($client_profile->getOther2() == '') {
             $ref = $this->genRandomString();
             $client_profile->setOther2($ref);
         }
         $this->form = new ClientQuickForm($client_profile);
         $client_login = sfGuardUserPeer::retrieveByPK($client_user_id);
         $this->client_login = $client_login;
         $c = new Criteria();
         $c->add(anotherContactPersonPeer::USER_ID, $client_user_id, Criteria::EQUAL);
         $this->another_contact_list = anotherContactPersonPeer::doSelect($c);
     } else {
         $ref = $this->genRandomString();
         $this->form = new ClientQuickForm();
         $this->form->setDefault('other2', $ref);
         $this->client_ranks = clientRankPeer::getClientOpportunityList($branch_id);
         $this->default_rank = 0;
         $this->default_sub_rank = null;
         $this->default_lead = 0;
         if (!empty($client_profile)) {
             $this->default_rank = $client_profile->getSubOpportunity() ? $client_profile->getSubOpportunity() : $client_profile->getRank();
             $this->default_lead = $client_profile->getLead();
         }
     }
     /*
      * save data to database
      */
     if ($request->isMethod('post')) {
         $form_data = $request->getParameter('profile');
         $prefered = null;
         if ($request->getParameter('preferedPhone')) {
             $prefered = $request->getParameter('preferedPhone');
         } elseif ($request->getParameter('preferedAfterHourPhone')) {
             $prefered = $request->getParameter('preferedAfterHourPhone');
         } elseif ($request->getParameter('preferedMobile')) {
             $prefered = $request->getParameter('preferedMobile');
         }
         $form_data['updated_at'] = date('Y-m-d H:i:s');
         $form_data['updated_by_id'] = $sf_user_id;
         $form_data['prefered_contact'] = $prefered;
         $form_data['user_id'] = $client_user_id;
         $sales_id = $form_data['sales_id'];
         if (!$sales_id) {
             $form_data['sales_id'] = $sf_user_id;
         } else {
             $form_data['sales_id'] = $sales_id;
         }
         if ($parent) {
             $sub_opportunity = $form_data['rank'];
             $sub_opportunities = SubOpportunityPeer::retrieveByPK($sub_opportunity);
             $opportunities = clientRankPeer::retrieveByPK($sub_opportunities->getOpportunityId());
             $form_data['rank'] = $opportunities->getRankId();
             $form_data['sub_opportunity'] = $sub_opportunity;
             if ($opportunities->getRankId() == 7) {
                 $form_data['lead'] = ClientLeadPeer::getBranchLostId($branch_id);
             }
         } else {
             $form_data['sub_opportunity'] = null;
         }
         $client_rank = $form_data['rank'] - 1;
         $this->project = null;
         if ($client_rank == 5) {
             $c = new Criteria();
             $c->add(pmProjectsPeer::CLIENT_ID, $client_user_id);
             $c->addDescendingOrderByColumn(pmProjectsPeer::CREATED_AT);
             $this->project = pmProjectsPeer::doSelectOne($c);
         }
         $this->form->bind($form_data);
         if ($this->form->isValid()) {
             $status = sfConfig::get('mod_client_opportunity_accountstatus');
             $form_data['account_status'] = accountStatusPeer::getStatusId($status[$client_rank]) + 1;
             if ($this->form->isNew()) {
                 $form_data['created_by_id'] = $sf_user_id;
                 $form_data['created_at'] = date('Y-m-d H:i:s');
                 $form_data['updated_at'] = date('Y-m-d H:i:s');
                 $form_data['updated_by_id'] = $sf_user_id;
                 /*
                  *  save client instance into sfguard
                  */
                 $sf_object = new sfGuardUser();
                 $tools_obj = new myTools();
                 /*
                  * login infomation
                  */
                 if (!array_key_exists('username', $login_details) || !$login_details['username']) {
                     $client_username = $tools_obj->RandomUsernameGenerator();
                     $sf_object->setUsername($client_username);
                 } else {
                     $sf_object->setUsername($login_details['username']);
                 }
                 if (!array_key_exists('password', $login_details) || !$login_details['password']) {
                     $sf_object->setPassword($tools_obj->randomPasswordGenerator());
                 } else {
                     $sf_object->setPassword($login_details['username']);
                 }
                 $sf_object->save();
                 $sf_object->addGroupByName('client');
                 $new_user_id = $sf_object->getId();
                 $form_data['user_id'] = $new_user_id;
                 $enquiry_details = new Inquiry();
                 $enquiry_details->setUserId($new_user_id);
                 if ($login_details['budget'] != '') {
                     $enquiry_details->setBudget($login_details['budget']);
                 }
                 if ($login_details['expected_close_date'] != '') {
                     $enquiry_details->setExpectedCloseDate(date('Y-m-d', strtotime($login_details['expected_close_date'])));
                 } elseif ($login_details['expected_close_date'] == '') {
                     $enquiry_details->setExpectedCloseDate(date('Y-m-d', strtotime(date('Y-m-01') . ' +6 month')));
                 }
                 $enquiry_details->save();
                 /*
                  *  save instance into branch users
                  */
                 $branch_object = new BranchUsers();
                 $branch_object->addBranchUser($new_user_id, $branch_id);
                 // set intance into company users
                 $company_object = new CompanyUsers();
                 $company_object->addCompanyUser($new_user_id, $company_id);
             } else {
                 $enquiry_id = InquiryPeer::getEnquiryId($client_user_id);
                 $enquiry_details = InquiryPeer::retrieveByPK($enquiry_id);
                 if ($enquiry_details) {
                     $enquiry_details->setBudget($login_details['budget']);
                     $enquiry_details->setExpectedCloseDate(date('Y-m-d', strtotime($login_details['expected_close_date'])));
                     $enquiry_details->save();
                 } else {
                     $enquiry_details = new Inquiry();
                     $enquiry_details->setUserId($client_login->getId());
                     if ($login_details['budget'] != '') {
                         $enquiry_details->setBudget($login_details['budget']);
                     }
                     if ($login_details['expected_close_date'] != '') {
                         $enquiry_details->setExpectedCloseDate(date('Y-m-d', strtotime($login_details['expected_close_date'])));
                     }
                     $enquiry_details->save();
                 }
                 if ($client_login) {
                     $client_login->setUsername($this->logindetails['username']);
                     if ($this->logindetails['password'] != '') {
                         $client_login->setPassword($this->logindetails['password']);
                     }
                     $client_login->save();
                     $new_user_id = $client_login->getId();
                 }
             }
             if ($login_details['signed_contract_value'] != '') {
                 $conn = Propel::getConnection();
                 //                    need update only one record in the furture
                 $cor = new Criteria();
                 $cor->add(pmProjectsPeer::CLIENT_ID, $client_user_id);
                 $cor->addDescendingOrderByColumn(pmProjectsPeer::CREATED_AT);
                 $cor_new = new Criteria();
                 $cor_new->add(pmProjectsPeer::ACTUAL_BUILD_COST, $login_details['signed_contract_value']);
                 $cor_new->add(pmProjectsPeer::UPDATED_BY_ID, $sf_user_id);
                 $cor_new->add(pmProjectsPeer::UPDATED_AT, date('Y-m-d H:i:s'));
                 BasePeer::doUpdate($cor, $cor_new, $conn);
             }
             /*
              * save the form to profile
              */
             $profile = $this->form->save();
             $profile->setUserId($new_user_id ? $new_user_id : $client_user_id);
             $profile->save();
             $old_opportunity_id = 0;
             $old_sub_opportunity_id = 0;
             $old_opportunity_id = $this->default_rank;
             $old_sub_opportunity_id = $this->default_sub_rank;
             $new_opp_record = false;
             $c_opp_record = new Criteria();
             $c_opp_record->add(ClientOpportunityRecordPeer::USER_ID, $client_user_id);
             if ($old_sub_opportunity_id) {
                 $c_opp_record->add(ClientOpportunityRecordPeer::SUB_OPPORTUNITY_ID, $old_sub_opportunity_id, Criteria::IN);
                 $opportunity_records = ClientOpportunityRecordPeer::doSelect($c_opp_record);
             } elseif ($old_opportunity_id) {
                 $c_opp_record->add(ClientOpportunityRecordPeer::OPPORTUNITY_ID, $old_opportunity_id, Criteria::IN);
                 $opportunity_records = ClientOpportunityRecordPeer::doSelect($c_opp_record);
             } else {
                 $opportunity_records = Null;
             }
             if (empty($opportunity_records)) {
                 $new_opp_record = true;
             }
             $new_opportunity_id = $profile->getRank();
             $new_sub_opportunity_id = $profile->getSubOpportunity();
             if ($new_opp_record) {
                 $client_opportunity_record = new ClientOpportunityRecord();
                 $client_opportunity_record->setOpportunityId($new_opportunity_id);
                 $client_opportunity_record->setSubOpportunityId($new_sub_opportunity_id);
                 $client_opportunity_record->setUserId($profile->getUserId());
                 $client_opportunity_record->setCreatedById($sf_user_id);
                 $client_opportunity_record->setUpdatedById($sf_user_id);
                 $client_opportunity_record->save();
             } else {
                 $conn = Propel::getConnection();
                 $client_opportunity_record_criteria = new Criteria();
                 $client_opportunity_record_criteria->add(ClientOpportunityRecordPeer::USER_ID, $profile->getUserId());
                 $client_opportunity_record_criteria->add(ClientOpportunityRecordPeer::OPPORTUNITY_ID, $new_opportunity_id);
                 $client_opportunity_record_criteria->add(ClientOpportunityRecordPeer::SUB_OPPORTUNITY_ID, $new_sub_opportunity_id);
                 $cor_new = new Criteria();
                 if ($new_opportunity_id == 6) {
                     if (!empty($this->getSignedContractDate)) {
                         $signed_updated_date = date('Y-m-d', strtotime($this->getSignedContractDate)) . ' ' . date('H:i:s');
                         $cor_new->add(ClientOpportunityRecordPeer::UPDATED_AT, $signed_updated_date);
                     }
                 } else {
                     $cor_new->add(ClientOpportunityRecordPeer::UPDATED_AT, date('Y-m-d H:i:s'));
                 }
                 $cor_new->add(ClientOpportunityRecordPeer::UPDATED_BY_ID, $sf_user_id);
                 BasePeer::doUpdate($client_opportunity_record_criteria, $cor_new, $conn);
             }
             if ($old_opportunity_id != $new_opportunity_id || $old_sub_opportunity_id != $new_sub_opportunity_id) {
                 $client_opportunity_log = new ClientOpportunityLog();
                 $client_opportunity_log->setUserId($profile->getUserId());
                 $client_opportunity_log->setOpportunityId($new_opportunity_id);
                 $client_opportunity_log->setSubOpportunityId($new_sub_opportunity_id);
                 $client_opportunity_log->setCreatedById($sf_user_id);
                 $client_opportunity_log->save();
             }
             /*
              *  delete record from another contact from current client
              */
             $c = new Criteria();
             $c->add(anotherContactPersonPeer::USER_ID, $profile->getUserId());
             $another = anotherContactPersonPeer::doDelete($c);
             // add record from client
             $another_details = $request->getParameter('contact_person');
             $no_of_fields = 5;
             $count_person_list = count($another_details) / $no_of_fields;
             $j = $no_of_fields;
             for ($i = 0; $i < $count_person_list - 1; $i++) {
                 $fname = $another_details[$j]['fname'];
                 $lname = $another_details[$j + 1]['lname'];
                 if ($fname != '' || $lname != '') {
                     $an_details = new anotherContactPerson();
                     $an_details->setUserId($profile->getUserId());
                     $an_details->setFname($another_details[$j++]['fname']);
                     $an_details->setLname($another_details[$j++]['lname']);
                     $an_details->setPhone($another_details[$j++]['phone']);
                     $an_details->setEmail($another_details[$j++]['email']);
                     $an_details->setMobile($another_details[$j++]['mobile']);
                     $an_details->save();
                 } else {
                     $j = $j + $no_of_fields;
                 }
             }
             if (!$request->getParameter('rdindex')) {
                 $profile_id = $profile->getId();
                 $profile_user_id = $profile->getUserId();
                 // save client details in the activity logs table
                 $modification_message = $this->form->isNew() ? 'Create Profile' : 'Update Profile';
                 $this->saveHistory($modification_message, $profile_user_id);
                 if ($this->form->isNew()) {
                     $reminder = sfConfig::get('mod_client_messages_msg4');
                     $sf_user->setFlash('notice', $reminder);
                     $this->redirect('client/show?id=' . $profile_id);
                 }
                 $client_info = sfConfig::get('mod_client_messages_msg2');
                 $sf_user->setFlash('notice', $client_info);
                 $this->redirect('client/show?id=' . $profile_id);
             }
             $profile_id = $profile->getId();
             $this->redirect('inquiry/edit?id=' . $profile_id);
         }
         if (isset($profile)) {
             $this->sub_opportunity_exist = $profile->getSubOpportunity() ? 1 : 0;
         }
         $this->setTemplate('edit');
     }
 }
Exemple #14
0
 public function getsfGuardUserRelatedByRecipientId($con = null)
 {
     if ($this->asfGuardUserRelatedByRecipientId === null && $this->recipient_id !== null) {
         include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardUserPeer.php';
         $this->asfGuardUserRelatedByRecipientId = sfGuardUserPeer::retrieveByPK($this->recipient_id, $con);
     }
     return $this->asfGuardUserRelatedByRecipientId;
 }
Exemple #15
0
 /**
  * Delete a person
  * Also deletes the person user and photo
  * @param PropelPDO $con
  */
 public function delete(PropelPDO $con = null)
 {
     $photo_path = $this->getPhotoFullPath();
     parent::delete($con);
     if ($this->getUserId()) {
         $user = sfGuardUserPeer::retrieveByPK($this->getUserId());
         $user->delete($con);
     }
     $this->deletePhysicalImage($photo_path);
 }
 public static function postReview($userId, $typeId, $entityId, $value, $text = false, $entity = false, $rm = false, $fb = '?', $source = '', $anonymous = '?', $tw = '?')
 {
     $prevValue = false;
     $guessAnonymous = $anonymous && $anonymous == '?' ? true : false;
     $guessFB = $fb && $fb == '?' ? true : false;
     $guessTW = $tw && $tw == '?' ? true : false;
     if ($guessAnonymous) {
         $user = sfGuardUserPeer::retrieveByPK($userId);
         if ($user) {
             $anonymous = $user->getProfile()->getAnonymous();
         }
     }
     if (!$entityId || !$value) {
         throw new Exception("Not enough parameters.");
     }
     if ($value != -1 && $value != 1) {
         throw new Exception("Invalid data for 'value'.");
     }
     // Check if already exists
     $c = new Criteria();
     if (!$typeId) {
         $c->add(SfReviewPeer::SF_REVIEW_ID, $entityId);
     } else {
         $c->add(SfReviewPeer::ENTITY_ID, $entityId);
     }
     $c->add(SfReviewPeer::SF_GUARD_USER_ID, $userId);
     $c->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $typeId ? $typeId : null);
     $review = SfReviewPeer::doSelectOne($c);
     if (!$review) {
         $review = new SfReview();
         if (!$typeId) {
             $review->setSfReviewId($entityId);
         } else {
             $review->setEntityId($entityId);
         }
         $review->setSfReviewTypeId($typeId ? $typeId : null);
         $review->setSfGuardUserId($userId);
         $review->setCreatedAt(new DateTime());
         $review->setSource($source);
     } else {
         if ($rm && $value == $review->getValue() && $review->getIsActive()) {
             $review->setIsActive(false);
         } else {
             $review->setIsActive(true);
         }
         $review->setModifiedAt(new DateTime());
     }
     $review->setValue($value);
     if ($text) {
         $aText = SfVoUtil::cutToLength($text, self::MAX_LENGTH, '');
         $aText = strip_tags($aText);
         $review->setText($aText);
     }
     $review->setSfReviewStatusId(1);
     $review->setIpAddress($_SERVER['REMOTE_ADDR']);
     $review->setCookie(sfContext::getInstance()->getRequest()->getCookie('symfony'));
     $review->setCulture(sfContext::getInstance()->getUser()->getCulture());
     if (!$guessFB) {
         $review->setToFb($fb);
     }
     if (!$guessTW) {
         $review->setToTw($tw);
     }
     if (!$guessAnonymous || $review->isNew()) {
         $review->setAnonymous($anonymous);
     }
     try {
         $review->save();
         if (!$typeId) {
             $parentReview = SfReviewPeer::retrieveByPk($entityId);
             $parentReview->setBalance(SfReviewManager::getBalanceByReviewId($entityId));
             $parentReview->save();
         }
         if (!$entity) {
             if (!$typeId) {
                 $aEntityId = $parentReview->getEntityId();
                 $aTypeId = $parentReview->getSfReviewTypeId();
             } else {
                 $aTypeId = $typeId;
                 $aEntityId = $entityId;
             }
             $reviewType = SfReviewTypePeer::retrieveByPK($aTypeId);
             $peer = $reviewType->getModel() . 'Peer';
             $entity = $peer::retrieveByPK($aEntityId);
         }
         $entity->updateCalcs();
         $entity->save();
     } catch (Exception $e) {
         throw new Exception('Error writing review.');
     }
     return $review->getIsActive() ? $review : false;
 }