Пример #1
0
    function indexAction()
    {
        $session = SessionWrapper::getInstance();
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(TRUE);
        $conn = Doctrine_Manager::connection();
        $formvalues = $this->_getAllParams();
        $userid = $session->getVar('userid');
        $companyid = getCompanyID();
        $acl = getACLInstance();
        $company_query = "";
        $company_query = " u.companyid = '" . $companyid . "' AND ";
        $q = $formvalues['searchword'];
        $html = '';
        $hasdata = false;
        // )
        # search users if loggedin user has access
        if ($acl->checkPermission('User Account', ACTION_LIST)) {
            $query = "SELECT u.id FROM useraccount as u \n\t\t\t\tWHERE " . $company_query . "\n\t\t\t   (u.firstname like '%" . $q . "%' or \n\t\t\t\tu.lastname like '%" . $q . "%' or \n\t\t\t\tu.othername like '%" . $q . "%' or \n\t\t\t\tu.displayname like '%" . $q . "%' or \n\t\t\t\tu.email like '%" . $q . "%' or \n\t\t\t\tu.phone like '%" . $q . "%' or \n\t\t\t\tu.username like '%" . $q . "%') \n\t\t\t\tGROUP BY u.id\n\t\t\t\torder by u.displayname asc LIMIT 5 ";
            // debugMessage($query);
            $result = $conn->fetchAll($query);
            $count_results = count($result);
            // debugMessage($result);
            if ($count_results > 0) {
                $hasdata = true;
                $html .= '<div class="separator"><span>Employees</span>
					<div class="allresults"><a href="' . $this->view->baseUrl('profile/list/searchterm/' . $q) . '" class="blockanchor">...see more results</a></div>
				</div><ul>';
                foreach ($result as $row) {
                    $user = new UserAccount();
                    $user->populate($row['id']);
                    $b_q = '<b>' . $q . '</b>';
                    $name = $user->getDisplayName();
                    $name = str_ireplace($q, $b_q, $name);
                    $position = getDatavariables('EMPLOYEE_POSITIONS', $user->getPosition(), true);
                    $phone = $user->getPhone();
                    $phone = str_ireplace($q, $b_q, $phone);
                    $email = $user->getEmail();
                    $email = str_ireplace($q, $b_q, $email);
                    $media = $user->getMediumPicturePath();
                    $viewurl = $this->view->baseUrl('profile/view/id/' . encode($row['id']));
                    $html .= '
					<li style="height:auto; min-height:90px;" class="display_box" align="left" url="' . $viewurl . '" theid="' . $row['id'] . '">
						<a href="' . $viewurl . '" style="color:#666; text-decoration:none;">
							<img class="imagecontainer" src="' . $media . '" style="width:78px; height:auto; float:left; margin-right:6px;" />
							<div style="margin-left: 70px;">
								<span class="name blocked">' . $name . '</span>
								<span class="name blocked">' . $position . '</span>
								<span class="blocked" style="margin-top:5px;">Email: ' . $email . '</span>
								<span class="blocked">Phone: ' . $phone . '</span>
								
							</div>
						</a>
					</li>';
                }
            }
        }
        # add navigation to searchable parameters
        $result = array('id' => 1, 'users' => '');
        # check no data is available for all areas and return no results message
        if (!$hasdata) {
            $html .= '
				<li class="display_box" align="center" style="height:30px;">
					<span style="width:100%; display:block; text-align:center;">No results for <b>' . $q . '</b></span>
				</li>';
        }
        $html .= '</ul>';
        echo $html;
    }
 function processnotificationAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $config = Zend_Registry::get("config");
     $message_collection = new Doctrine_Collection(Doctrine_Core::getTable("Message"));
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit;
     $recipients_array = array();
     $messagedata = array();
     $users = array();
     $execresult = array('result' => '', 'msg' => '');
     $type = $formvalues['type'];
     if ($type == 1) {
         $ismail = true;
         $issms = false;
         $msgtype = "mail";
     }
     if ($type == 2) {
         $issms = true;
         $ismail = false;
         $msgtype = "sms";
     }
     $custom_query = "";
     if ($formvalues['selecttype'] == 2) {
         if (!isArrayKeyAnEmptyString('userids', $formvalues)) {
             $users = $formvalues['userids'];
         }
     }
     if ($formvalues['selecttype'] == 4) {
         if ($ismail) {
             $users = getUsersWithEmail();
         }
         if ($issms) {
             $users = getUsersWithPhone();
         }
     }
     //debugMessage($users); exit;
     # if no receipients specified
     if (count($users) == 0) {
         $session->setVar(ERROR_MESSAGE, "Error: No Receipients specified!");
         $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
         $execresult = array('result' => 'fail', 'msg' => "Error: No Receipients specified!");
         exit;
     }
     $messages = array();
     $sent = array();
     $phones = array();
     $messages['contents'] = $formvalues['contents'];
     $messages['type'] = $formvalues['type'];
     if (!isArrayKeyAnEmptyString('subject', $formvalues)) {
         $messages['subject'] = $formvalues['subject'];
     } else {
         $messages['subject'] = '';
     }
     $messages['senderid'] = 0;
     if (!isArrayKeyAnEmptyString('senderid', $formvalues)) {
         $messages['senderid'] = $formvalues['senderid'];
     }
     if (!isArrayKeyAnEmptyString('senderemail', $formvalues) && isEmptyString($session->getVar('userid'))) {
         $messages['senderemail'] = $formvalues['senderemail'];
     }
     if (!isArrayKeyAnEmptyString('sendername', $formvalues) && isEmptyString($session->getVar('userid'))) {
         $messages['sendername'] = $formvalues['sendername'];
     }
     # process receipients depending on select type
     foreach ($users as $key => $userid) {
         $user = new UserAccount();
         $id = '';
         if ($formvalues['selecttype'] == 2) {
             $id = $userid;
         }
         if ($formvalues['selecttype'] == 4) {
             $id = $key;
         }
         $user->populate($id);
         // debugMessage($memb->toArray());
         $recipients_array[$id]['recipientid'] = $user->getID();
         $messagedata[$id]['id'] = $user->getID();
         $messagedata[$id]['name'] = $user->getName();
         $messagedata[$id]['email'] = $user->getEmail();
         $messagedata[$id]['phone'] = $user->getPhone();
         $messagedata[$id]['sendemail'] = $user->allowEmailForPrivateMessage() ? 1 : 0;
         if ($ismail) {
             $sent[] = $user->getName() . ' (' . $user->getEmail() . ')';
         }
         if ($issms) {
             $sent[] = $user->getName() . ' (' . $user->getPhone() . ')';
             $phones[] = $user->getPhone();
         }
     }
     $messages['recipients'] = $recipients_array;
     $messages['membertotal'] = count($messagedata);
     $messages['usertotal'] = count($recipients_array);
     $messages['type'] = "notification";
     $messages['subtype'] = "new_" . $msgtype;
     /* debugMessage($sent); 
     		debugMessage($messagedata);  */
     $msg = new Message();
     $msg->processPost($messages);
     /* debugMessage($msg->toArray());
     		debugMessage('error is '.$msg->getErrorStackAsString()); exit(); */
     // save the messages to system inbox
     if ($msg->hasError()) {
         $session->setVar(ERROR_MESSAGE, "Error: " . $msg->getErrorStackAsString());
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
         $execresult = array('result' => 'fail', 'msg' => "Error: " . $msg->getErrorStackAsString());
         // debugMessage($execresult);
         exit;
     } else {
         try {
             $msg->save();
             // send message to emails
             if (count($messagedata) > 0) {
                 foreach ($messagedata as $key => $receipient) {
                     $msgdetail = new MessageRecipient();
                     if (!isArrayKeyAnEmptyString('email', $receipient) && $receipient['sendemail'] == 1) {
                         $msgdetail->sendInboxEmailNotification($formvalues['senderemail'], $formvalues['sendername'], $messages['subject'], $receipient['email'], $receipient['name'], $messages['contents']);
                     }
                 }
             }
             // send message to phones
             if (count($phones) > 0) {
                 $messagechuncks = array_chunk($messagedata, 100, true);
                 if (count($messagedata) <= 100) {
                     $phonelist = implode(',', $phones);
                     //$result = sendSMSMessage($phonelist, $messages['contents'], '', $msg->getID());
                     // debugMessage($result); exit;
                 } else {
                     foreach ($messagechuncks as $key => $messagegrp) {
                         $phones_temp_array = array();
                         foreach ($messagegrp as $keynest => $messageline) {
                             $phones_temp_array[] = $messageline['phone'];
                         }
                         $phonelist = implode(',', $phones_temp_array);
                         // $result = sendSMSMessage($phonelist, $messages['contents'], '', $msg->getID());
                         // debugMessage($result);
                     }
                 }
             }
             if (count($messagedata) == 1) {
                 $key = current(array_keys($messagedata));
                 if ($ismail) {
                     $rcpt = $messagedata[$key]['name'] . ' (' . $messagedata[$key]['email'] . ')';
                     $sentmessage = "Message sent to " . $rcpt;
                     $session->setVar(SUCCESS_MESSAGE, $sentmessage);
                 }
                 if ($issms) {
                     $rcpt = $messagedata[$key]['name'] . ' (' . $messagedata[$key]['phone'] . ')';
                     $sentmessage = "Message sent to " . $rcpt;
                     $session->setVar(SUCCESS_MESSAGE, $sentmessage);
                 }
             } else {
                 $sentmessage = "Message successfully sent to <b>" . count($messagedata) . "</b> member(s). <br />See full list of recipient(s) at the bottom of this page.";
                 $sentresult = createHTMLListFromArray($sent, 'successmsg alert alert-success');
                 $session->setVar('sentlist', $sentresult);
                 $session->setVar(SUCCESS_MESSAGE, "Message sent to " . count($messagedata) . " members. <br />See full list of recipients at the bottom of this page.");
             }
             $execresult = array('result' => 'success', 'msg' => $sentmessage);
         } catch (Exception $e) {
             $session->setVar(ERROR_MESSAGE, "An error occured in sending the message. " . $e->getMessage());
             $session->setVar(FORM_VALUES, $this->_getAllParams());
             $execresult = array('result' => 'success', 'msg' => "An error occured in sending the message. " . $e->getMessage());
         }
     }
     // exit;
     $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
     echo json_encode($execresult);
 }