/**
  * Query
  *
  * @param array $args
  * @return Doctrine_Query $q
  */
 protected function air_query($args = array())
 {
     $q = Doctrine_Query::create()->from('InqOutcome io');
     $q->where('io.iout_out_id = ?', $this->parent_rec->out_id);
     $q->leftJoin('io.Inquiry i');
     $q->leftJoin('io.CreUser c');
     Inquiry::add_counts($q, 'i');
     $q->addSelect('(i.inq_publish_dtim is not null) as ispub');
     return $q;
 }
 /**
  * Query
  *
  * @param array $args
  * @return Doctrine_Query $q
  */
 protected function air_query($args = array())
 {
     $prj_id = $this->parent_rec->prj_id;
     $q = Doctrine_Query::create()->from('ProjectInquiry pi');
     $q->where('pi.pinq_prj_id = ?', $prj_id);
     $q->leftJoin('pi.Inquiry i');
     $q->leftJoin('i.CreUser u');
     $q->leftJoin('u.UserOrg uo WITH uo.uo_home_flag = true');
     $q->leftJoin('uo.Organization o');
     $q->addSelect('i.inq_uuid as inq_uuid');
     Inquiry::add_counts($q, 'i');
     // prevent record-wise limit (fixes limit subquery)
     $q->getRoot()->setAttribute(Doctrine_Core::ATTR_QUERY_LIMIT, Doctrine_Core::LIMIT_ROWS);
     return $q;
 }
 /**
  * Fetch
  *
  * @param string $uuid
  * @return Doctrine_Record $rec
  */
 protected function air_fetch($uuid)
 {
     $q = Doctrine_Query::create()->from('Inquiry i');
     $q->andWhere('i.inq_id = ?', $this->parent_rec->srs_inq_id);
     // some more stuff
     $q->leftJoin('i.CreUser icu');
     $q->leftJoin('icu.UserOrg icuo WITH icuo.uo_home_flag = true');
     $q->leftJoin('icuo.Organization o');
     $q->leftJoin('i.ProjectInquiry pi');
     $q->leftJoin('pi.Project');
     $q->leftJoin('i.InqOrg io');
     $q->leftJoin('io.Organization ioo');
     Inquiry::add_counts($q, 'i');
     return $q->fetchOne();
 }
 /**
  * Returns array of Inquiry records that comprise the RSS feed
  * for this Project.
  *
  * @param integer $limit (optional) default is 100
  * @return unknown
  */
 public function get_inquiries_in_rss_feed($limit = 100)
 {
     // make sure we have an integer
     if (!isset($limit)) {
         $limit = 100;
     }
     $q = Inquiry::get_base_query_for_published();
     $q->innerJoin('i.ProjectInquiry pi');
     $q->innerJoin('pi.Project p');
     $q->andWhereIn('pi.pinq_status', array('A'));
     $q->andWhere('i.inq_rss_status = ?', 'Y');
     $q->andWhere('p.prj_id = ?', $this->prj_id);
     if ($limit) {
         $q->limit($limit);
     }
     $q->orderBy('i.inq_publish_dtim desc');
     return $q->execute();
 }
 /**
  * Apply authz rules for who may write.
  *
  * @param AIR2_Query $q
  * @param User    $u
  * @param string  $alias (optional)
  */
 public static function query_may_write(AIR2_Query $q, User $u, $alias = null)
 {
     if ($u->is_system()) {
         return;
     }
     $a = $alias ? "{$alias}." : "";
     // readable inquiries
     $tmp = AIR2_Query::create();
     Inquiry::query_may_read($tmp, $u);
     $tmp = array_pop($tmp->getDqlPart('where'));
     $inq_ids = "select inq_id from inquiry where {$tmp}";
     // add to query
     $user_id = $u->user_id;
     $own = "{$a}inqan_cre_user = {$user_id}";
     $q->addWhere("({$a}inqan_inq_id in ({$inq_ids}) and {$own})");
 }
 /**
  * Override the base rec_update, to handle potential cache-writes
  *
  * @param Inquiry $rec
  * @param array   $data
  */
 protected function rec_update(Inquiry $rec, $data)
 {
     $rec->inq_stale_flag = true;
     //mark as stale
     // validate actions
     if (isset($data['do_deactivate'])) {
         if ($rec->is_published()) {
             $msg = 'Cannot deactivate a published query';
             throw new Rframe_Exception(Rframe::BAD_DATA, $msg);
         }
         if ($rec->inq_status == Inquiry::$STATUS_INACTIVE) {
             $msg = 'Cannot deactivate an inactive query';
             throw new Rframe_Exception(Rframe::BAD_DATA, $msg);
         }
     }
     if (isset($data['do_deactivate']) && isset($data['do_publish'])) {
         $msg = 'Cannot deactivate AND publish a query';
         throw new Rframe_Exception(Rframe::BAD_DATA, $msg);
     }
     //TODO: lots of error checking needed
     if (isset($data['do_schedule'])) {
         $rec->inq_status = Inquiry::$STATUS_SCHEDULED;
     }
     if (isset($data['do_unschedule'])) {
         $rec->inq_status = Inquiry::$STATUS_DRAFT;
     }
     if (isset($data['loc_key'])) {
         $tbl = Doctrine::getTable('Locale');
         $col = 'loc_key';
         $locale = $tbl->findOneBy($col, $data['loc_key']);
         if ($locale) {
             $rec->inq_loc_id = $locale->loc_id;
         }
     }
     if (isset($data['logo'])) {
         try {
             if (!$rec->Logo) {
                 $rec->Logo = new ImageInqLogo();
             }
             $rec->Logo->set_image($data['logo']);
         } catch (Exception $e) {
             throw new Rframe_Exception(RFrame::BAD_DATA, $e->getMessage());
         }
     }
     // delete logo if null is passed
     if (array_key_exists('logo', $data) && !$data['logo']) {
         if ($rec->Logo) {
             $rec->Logo->delete();
             $rec->clearRelated('Logo');
         }
     }
     // update columns
     foreach ($data as $key => $val) {
         if ($rec->getTable()->hasColumn($key)) {
             $rec->{$key} = $val;
         }
     }
     // authz
     $this->check_authz($rec, 'write');
     $this->air_save($rec);
     // actions!
     if (isset($data['do_publish'])) {
         $rec->do_publish();
     }
     if (isset($data['do_deactivate'])) {
         $rec->do_deactivate();
     }
     if (isset($data['do_expire'])) {
         $rec->do_expire();
     }
 }
 $personInfo->citizenship = $_POST['a_citizenship'];
 $personInfo->birthday = strtotime($_POST['a_birthday']);
 $personInfo->email = $_POST['a_email'];
 $personInfo->contactnumber1 = $_POST['a_contactnumber1'];
 $personInfo->contactnumber2 = $_POST['a_contactnumber2'];
 $personInfo->contactnumber3 = $_POST['a_contactnumber3'];
 $personInfo->emergencycontactperson = $_POST['a_emergencycontactperson'];
 $personInfo->update();
 //----------------------------------------------------------------------------------------------------------------------------------//
 $schoolLastAttended = SchoolLastAttended::get_by_id($student->school_last_attended_id);
 $schoolLastAttended->school = $_POST['b_schoolname'];
 $schoolLastAttended->schoolyear = $_POST['b_schoolyear'];
 $schoolLastAttended->program = $_POST['b_program'];
 $schoolLastAttended->update();
 //----------------------------------------------------------------------------------------------------------------------------------//
 $inquiry = Inquiry::get_by_id($student->inquiry_id);
 $inquiry->tuition = $_POST['c_tuition'];
 $inquiry->program = $_POST['c_program'];
 $inquiry->others = $_POST['c_others'];
 $inquiry->update();
 //----------------------------------------------------------------------------------------------------------------------------------//
 $schoolConsidered = SchoolConsidered::get_by_id($student->school_considered_id);
 $schoolConsidered->first = $_POST['d_first'];
 $schoolConsidered->second = $_POST['d_second'];
 $schoolConsidered->third = $_POST['d_third'];
 $schoolConsidered->update();
 //----------------------------------------------------------------------------------------------------------------------------------//
 $discovery = StiDiscovery::get_by_id($student->sti_discovery_id);
 $discovery->tv = $_POST['e_tv'];
 $discovery->radio = $_POST['e_radio'];
 $discovery->print = $_POST['e_print'];
 /**
  * Returns array of Inquiry records that comprise the RSS feed
  * for this Organization.
  *
  * @param integer $limit         (optional) default is 100
  * @param unknown $ignore_src_id (optional)
  * @param unknown $class         (optional)
  * @return array $inquiries
  */
 public function get_inquiries_in_rss_feed($limit = 100, $ignore_src_id = null, $class = 'Inquiry')
 {
     // make sure we have an integer
     if (!isset($limit)) {
         $limit = 100;
     }
     $q = Inquiry::get_base_query_for_published($class);
     $q->innerJoin('i.InqOrg io');
     $q->andWhereIn('io.iorg_status', array('A'));
     $q->andWhere('i.inq_rss_status = ?', 'Y');
     $q->andWhere('io.iorg_org_id = ?', $this->org_id);
     if ($ignore_src_id) {
         $q->andWhere("i.inq_id not in (select srs_inq_id from src_response_set where srs_src_id = ?)", $ignore_src_id);
     }
     if ($limit) {
         $q->limit($limit);
     }
     $q->orderBy('i.inq_publish_dtim desc');
     return $q->execute();
 }
Example #9
0
 public function createFollowup()
 {
     $inputs = Input::all();
     if ($inputs['followupType'] == 'COMPLAINTS') {
         $createComplaint = Complaint::createComplaint($inputs);
         $input['complaint_id'] = $createComplaint->id;
     } else {
         if ($inputs['followupType'] == 'RETENTION') {
             $createRetention = Retention::createRetention($inputs);
             $input['retention_id'] = $createRetention->id;
         } else {
             if ($inputs['followupType'] == 'INQUIRY') {
                 $createInquiry = Inquiry::createInquiry($inputs);
                 $input['inquiry_id'] = $createInquiry->id;
             }
         }
     }
     //create comment
     if (isset($createComplaint)) {
         $input['customerId'] = $inputs['customer_id'];
         $input['student_id'] = $inputs['student_id'];
         $input['followupType'] = $inputs['followupType'];
         $input['commentStatus'] = $inputs['followupstatus'];
         $input['commentText'] = $inputs['otherCommentTxtarea'];
         $input['commentType'] = $inputs['comment_type'];
         $input['reminderDate'] = $inputs['remindDate'];
         $comments_data = Comments::addComments($input);
     }
     if (isset($createRetention)) {
         $input['customerId'] = $inputs['customer_id'];
         $input['student_id'] = $inputs['student_id'];
         $input['followupType'] = $inputs['followupType'];
         $input['commentStatus'] = $inputs['followupstatus'];
         $input['commentText'] = $inputs['otherCommentTxtarea'];
         $input['commentType'] = $inputs['comment_type'];
         $input['reminderDate'] = $inputs['remindDate'];
         $comments_data = Comments::addComments($input);
     }
     if (isset($createInquiry)) {
         $input['customerId'] = $inputs['customer_id'];
         $input['followupType'] = $inputs['followupType'];
         $input['commentStatus'] = $inputs['followupstatus'];
         $input['commentText'] = $inputs['otherCommentTxtarea'];
         $input['commentType'] = $inputs['comment_type'];
         $input['reminderDate'] = $inputs['remindDate'];
         $comments_data = Comments::addComments($input);
     }
     if ($comments_data) {
         return Response::json(array('status' => 'success'));
     } else {
         return Response::json(array('status' => 'failure'));
     }
 }
Example #10
0
 static function getInquiryByCustomerId($customerId)
 {
     return Inquiry::where('customer_id', '=', $customerId)->where('franchisee_id', '=', Session::get('franchiseId'))->get();
 }
Example #11
0
 public function details($id)
 {
     if (Auth::check()) {
         $currentPage = "CUSTOMERS_LIST";
         $mainMenu = "CUSTOMERS_MAIN";
         $inputs = Input::all();
         if (isset($inputs['customerName'])) {
             if (Customers::addCustomers($inputs)) {
                 Session::flash('msg', "Customer added successfully.");
             } else {
                 Session::flash('warning', "Customer, Course Could not be added at the moment.");
             }
         }
         $customer = Customers::getCustomersById($id);
         $students = Students::getStudentByCustomer($id);
         $comments = Comments::getCommentByCustomerId($id);
         $provinces = Provinces::getProvinces("IN");
         $kidsSelect = Students::getStudentsForSelectBox($id);
         $membershipTypes = MembershipTypes::getMembershipTypesForSelectBox();
         $birthdays = BirthdayParties::getBirthdaysByCustomer($id);
         //return $customer;
         //Membership
         if (isset($inputs['membershipTypesMembersDiv'])) {
             /* echo '<pre>';
             			print_r($inputs);
             			echo '</pre>';
             			exit(); */
             if ($inputs['membershipTypesMembersDiv'] != "") {
                 $membershipInput['customer_id'] = $id;
                 $membershipInput['membership_type_id'] = $inputs['membershipTypesMembersDiv'];
                 CustomerMembership::addMembership($membershipInput);
                 $order['customer_id'] = $id;
                 $order['payment_for'] = "membership";
                 $order['payment_dues_id'] = '';
                 $order['payment_mode'] = $inputs['paymentTypeRadio'];
                 $order['card_last_digit'] = $inputs['card4digits'];
                 $order['card_type'] = $inputs['cardType'];
                 $order['bank_name'] = $inputs['bankName'];
                 $order['cheque_number'] = $inputs['chequeNumber'];
                 $order['amount'] = $inputs['membershipPrice'];
                 $order['order_status'] = "completed";
                 Orders::createOrder($order);
             }
         }
         //$customerMembership = "";
         /* echo '<pre>';
         			print_r($customer);
         			echo '</pre>';
         			exit(); */
         $presentDate = Carbon::now();
         $membershipStartDate = Carbon::now();
         $membershipEndDate = Carbon::now();
         $customerMembershipId = '';
         if (isset($customer->CustomerMembership['0'])) {
             $select = count($customer->CustomerMembership) - 1;
             $membershipStartDate = $membershipStartDate->createFromFormat('Y-m-d', $customer->CustomerMembership[$select]->membership_start_date);
             $membershipEndDate = $membershipEndDate->createFromFormat('Y-m-d', $customer->CustomerMembership[$select]->membership_end_date);
             if ($membershipStartDate->lte($presentDate) && $membershipEndDate->gte($presentDate)) {
                 $customerMembershipId = $customer->CustomerMembership[$select]->membership_type_id;
             }
         }
         if (isset($customerMembershipId)) {
             $customerMembership = MembershipTypes::getMembershipTypeByID($customerMembershipId);
         }
         $membershipTypesAll = MembershipTypes::getMembershipTypes();
         $birthdaypaiddata = Orders::getBirthdayfulldata($id);
         for ($i = 0; $i < count($birthdaypaiddata); $i++) {
             $studentData = Students::getStudentById($birthdaypaiddata[$i]['student_id']);
             $birthdaypaiddata[$i]['student_name'] = $studentData[0]['student_name'];
             $birthdaypaiddata[$i]['student_date_of_birth'] = $studentData[0]['student_date_of_birth'];
             $birthdayData = BirthdayParties::getBirthdaybyId($birthdaypaiddata[$i]['birthday_id']);
             $birthdaypaiddata[$i]['birthday_party_date'] = $birthdayData[0]['birthday_party_date'];
             $birthdaypaiddata[$i]['tax_amount'] = $birthdaypaiddata[0]['tax_amount'];
             $user_data = User::getUsersByUserId($birthdaypaiddata[$i]['created_by']);
             $birthdaypaiddata[$i]['name'] = $user_data[0]['first_name'] . $user_data[0]['last_name'];
             $birthdaypaiddata[$i]['encrypted_id'] = Crypt::encrypt($birthdaypaiddata[$i]['id']);
         }
         $birthdayDuedata = PaymentDues::getPaymentpendingfulldata($id);
         for ($i = 0; $i < count($birthdayDuedata); $i++) {
             $studentData = Students::getStudentById($birthdayDuedata[$i]['student_id']);
             $birthdayDuedata[$i]['student_name'] = $studentData[0]['student_name'];
             $user_data = User::getUsersByUserId($birthdayDuedata[$i]['created_by']);
             $birthdayDuedata[$i]['name'] = $user_data[0]['first_name'] . $user_data[0]['last_name'];
             $birthdayData = BirthdayParties::getBirthdaybyId($birthdayDuedata[$i]['birthday_id']);
             $birthdayDuedata[$i]['birthday_party_date'] = $birthdayData[0]['birthday_party_date'];
         }
         //followup_data
         $iv_data = IntroVisit::where('customer_id', '=', $id)->get();
         for ($i = 0; $i < count($iv_data); $i++) {
             $comments_data = Comments::where('introvisit_id', '=', $iv_data[$i]['id'])->orderBy('id', 'DESC')->first();
             $iv_data[$i]['comment_data'] = $comments_data;
             $student = Students::find($iv_data[$i]['student_id']);
             $iv_data[$i]['student_name'] = $student['student_name'];
             $iv_data[$i]['iv_date'] = date("Y-m-d", strtotime($iv_data[$i]['iv_date']));
         }
         $birthday_data = BirthdayParties::where('customer_id', '=', $id)->get();
         for ($i = 0; $i < count($birthday_data); $i++) {
             $birthday_comments = Comments::where('birthday_id', '=', $birthday_data[$i]['id'])->orderBy('id', 'DESC')->first();
             $birthday_data[$i]['comment_data'] = $birthday_comments;
             $student_data = Students::find($birthday_data[$i]['student_id']);
             $birthday_data[$i]['student_name'] = $student_data['student_name'];
             $birthday_data[$i]['birthday_party_date'] = date("Y-m-d", strtotime($birthday_data[$i]['birthday_party_date']));
         }
         //for complaints
         $complaint_data = Complaint::getComplaintByCustomerId($id);
         //Comments::where('customer_id','=',$id)->get();
         for ($i = 0; $i < count($complaint_data); $i++) {
             $complaint_data[$i]['comments'] = Comments::where('complaint_id', '=', $complaint_data[$i]['id'])->orderBy('id', 'DESC')->first();
             $student_data = Students::find($complaint_data[$i]['student_id']);
             $complaint_data[$i]['student_name'] = $student_data['student_name'];
         }
         //for retention
         $retention_data = Retention::getRetentionByCustomerId($id);
         for ($i = 0; $i < count($retention_data); $i++) {
             $retention_data[$i]['comments'] = Comments::where('retention_id', '=', $retention_data[$i]['id'])->orderBy('id', 'DESC')->first();
             $student_data = Students::find($retention_data[$i]['student_id']);
             $retention_data[$i]['student_name'] = $student_data['student_name'];
         }
         //for inquiry
         $inuiry_data = Inquiry::getInquiryByCustomerId($id);
         for ($i = 0; $i < count($inuiry_data); $i++) {
             $inuiry_data[$i]['comments'] = Comments::where('inquiry_id', '=', $inuiry_data[$i]['id'])->orderBy('id', 'DESC')->first();
         }
         //for enrollment payment followup/brush up calls
         $enrollmentFollowupData = PaymentFollowups::getPaymentFollowupByCustomerId($id);
         for ($i = 0; $i < count($enrollmentFollowupData); $i++) {
             $enrollmentFollowupData[$i]['comments'] = Comments::where('paymentfollowup_id', '=', $enrollmentFollowupData[$i]['id'])->orderBy('id', 'DESC')->first();
             $student_data = Students::find($enrollmentFollowupData[$i]['student_id']);
             $enrollmentFollowupData[$i]['student_name'] = $student_data['student_name'];
             $paymentDueData = PaymentDues::find($enrollmentFollowupData[$i]['payment_due_id']);
             $enrollmentFollowupData[$i]['payment_date'] = $paymentDueData['end_order_date'];
         }
         // for customer kids enrollment.
         $customer_student_data = Students::where('customer_id', '=', $id)->where('franchisee_id', '=', Session::get('franchiseId'))->select('id', 'student_name')->get();
         for ($i = 0; $i < count($customer_student_data); $i++) {
             $student_classes = StudentClasses::getEnrolledStudentBatch($customer_student_data[$i]['id']);
             //return $student_classes[0]['batch_id'];
             $customer_student_data[$i]['student_classes_data'] = $student_classes;
         }
         //return $customer_student_data;
         for ($i = 0; $i < count($customer_student_data); $i++) {
             for ($j = 0; $j < count($customer_student_data[$i]['student_classes_data']); $j++) {
                 $find = Batches::find($customer_student_data[$i]['student_classes_data'][$j]['batch_id']);
                 $customer_student_data[$i]['student_classes_data'][$j]['batch_name'] = $find->batch_name;
             }
         }
         //return the customer membership follolwup
         $customer_membership_data = MembershipFollowup::where('customer_id', '=', $id)->get();
         for ($i = 0; $i < count($customer_membership_data); $i++) {
             $membershipid[$i] = $customer_membership_data[$i]['id'];
         }
         if (isset($membershipid)) {
             for ($i = 0; $i < count($membershipid); $i++) {
                 $membership_followup_data[$i] = Comments::where('membership_followup_id', '=', $membershipid[$i])->orderBy('id', 'DESC')->first();
                 $memfollowup_data = MembershipFollowup::find($membershipid[$i]);
                 $Customer_membership_data = CustomerMembership::find($memfollowup_data->membership_id);
                 $membership_followup_data[$i]['membership_end_date'] = $Customer_membership_data->membership_end_date;
             }
         }
         $viewData = array('birthdaypaiddata', 'birthdayDuedata', 'customer', 'students', 'currentPage', 'mainMenu', 'comments', 'provinces', 'customerMembership', 'kidsSelect', 'membershipTypes', 'membershipTypesAll', 'birthdays', 'iv_data', 'birthday_data', 'complaint_data', 'retention_data', 'inuiry_data', 'enrollmentFollowupData', 'customer_student_data', 'membership_followup_data');
         return View::make('pages.customers.details', compact($viewData));
     } else {
         return Redirect::to("/");
     }
 }
Example #12
0
<!DOCTYPE html>
<html>
	<head>
		<title>Retrieving info from a Form</title>
	</head>
	<body>
		<h1>Inquiries</h1>
		<?php 
require 'class.Inquiry.inc';
$inquiry = new Inquiry($_GET['Name'], $_GET['Email'], $_GET['Subject'], $_GET['Message']);
$inquiry->displayFull();
?>
	</body>
</html>
 /**
  * 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');
     }
 }
 /**
  * Returns AIR2_Query object for published Inquiries.
  *
  * @param string  $class (optional)
  * @return AIR2_Query $q
  */
 public static function get_base_query_for_published($class = 'Inquiry')
 {
     $now = air2_date();
     $q = AIR2_Query::create()->from("{$class} i")->whereIn("i.inq_type", array(self::$TYPE_FORMBUILDER, self::$TYPE_QUERYBUILDER, self::$TYPE_TEST, self::$TYPE_NONJOURN))->andWhereIn('i.inq_status', Inquiry::published_status_flags())->andWhere("(i.inq_publish_dtim is null OR i.inq_publish_dtim <= '{$now}')")->andWhere("(i.inq_expire_dtim is null OR i.inq_expire_dtim > '{$now}')")->andWhere("(i.inq_deadline_dtim is null OR i.inq_deadline_dtim > '{$now}')");
     return $q;
 }
 /**
  * RSS feed for displaying a project's - or multiple projects' - inquiries.
  *
  * @return void
  * @param string  $prj_name (optional)
  */
 public function project($prj_name = null)
 {
     // only RSS available
     $this->airoutput->view = 'rss';
     $this->airoutput->format = 'application/rss+xml';
     $project = null;
     $inquiries = null;
     if ($prj_name) {
         // Sanitize and standardize prj_name.
         $prj_name = strtolower($prj_name);
         // Get actual project, to tailor the feed.
         $q = Doctrine_Query::create()->from('Project p');
         $q->leftJoin('p.OrgDefault');
         $q->andWhere('lower(prj_name) = ?', $prj_name);
         $project = $q->fetchOne();
         if (!$project) {
             show_404();
             return;
         }
         $inquiries = $project->get_inquiries_in_rss_feed();
     } else {
         $inquiries = Inquiry::get_all_published_rss();
     }
     // Publish date of the feed. Default to now, in case there are no inquiries.
     $pub_date = $this->_rss_datetime();
     if (count($inquiries) > 0) {
         // Use the publish date and time of the most recent inquiry as the
         // publish date-time of the feed.
         $pub_date = $this->_rss_datetime($inquiries[0]->inq_publish_dtim);
     }
     $items = $this->_build_inquiries_feed($inquiries);
     // defaults
     $title = 'Queries from the Public Insight Network';
     $description = 'Answer these questions to inform Public Insight Network reporting.  Share what you know!';
     $link = 'http://www.publicinsightnetwork.org';
     $logo_uri = 'http://www.publicinsightnetwork.org/user/signup/support/standard/images/apm.jpg';
     $cache_path = Project::get_combined_rss_cache_path();
     // override defaults is we were asked for a specific project
     if ($project && count($project->OrgDefault) > 0) {
         $org = $project->OrgDefault[0];
         $logo = $org->Logo;
         if ($logo) {
             $logo_uris = $logo->get_image(true);
             if (trim($logo_uris['original'])) {
                 $logo_uri = $logo_uris['original'];
             }
         }
         if (strlen($org->org_summary)) {
             $description = $org->org_summary;
         }
         if (strlen($org->org_site_uri)) {
             $link = $org->org_site_uri;
         }
     }
     // title and cache regardless of OrgDefault
     if ($project) {
         $title = $project->prj_display_name;
         $cache_path = $project->get_rss_cache_path();
     }
     $this->_build_response($items, $title, $description, $link, $logo_uri, $pub_date, $cache_path);
 }
Example #16
0
<?php

return function ($site, $pages, $page) {
    $alert = null;
    if (get('submit')) {
        $data = array('fname' => get('fname'), 'lname' => get('lname'), 'email' => get('email'), 'website' => get('website'), 'instagram' => get('instagram'), 'budget' => get('budget'), 'message' => get('message'));
        $rules = array('fname' => array('required'), 'lname' => array('required'), 'email' => array('required', 'email'), 'website' => array('required'), 'budget' => array('required'), 'message' => array('required', 'min' => 3, 'max' => 5000));
        $messages = array('fname' => 'Please enter a valid first name', 'lname' => 'Please enter a valid last name', 'email' => 'Please enter a valid email address', 'website' => 'Please enter a website url', 'budget' => 'Please enter your budget', 'message' => 'Please enter a message between 3 and 5000 characters');
        // some of the data is invalid
        if ($invalid = invalid($data, $rules, $messages)) {
            $alert = $invalid;
            // the data is fine, let's send the email
        } else {
            // create the body from a simple snippet
            $body = snippet('inquirymail', $data, true);
            // build the email
            $email = new Inquiry(array('to' => '*****@*****.**', 'from' => '*****@*****.**', 'subject' => 'New Inquiry', 'replyTo' => $data['email'], 'body' => $body));
            // try to send it and redirect to the
            // thank you page if it worked
            if ($email->send()) {
                go('project-planner/thank-you');
                // add the error to the alert list if it failed
            } else {
                $alert = array($email->error());
            }
        }
    }
    return compact('alert');
};