/** * See messages sent to a particular folder. * * @access public */ public function viewAction() { // Defaults $error = null; $foldername = 'Not Found'; $folderid = null; $subscribers = array(); $message = null; $datauploaded = 0; $folderList = $this->user->getFolders(); $id = $this->request->getParam('id'); $from = $this->request->getParam('from'); if ($from && $from == 'keyword') { $link = '/messages/keyword/'; $kid = $this->request->getParam('kid'); $keyword = $this->request->getParam('keyword'); if ($kid && $keyword) { $link .= 'id/' . $kid; $text = 'Back to keyword ' . $keyword; } else { $text = 'Back to keywords'; } } else { $link = '/folder/'; $text = 'Back to folders'; } $this->view->backtolink = $link; $this->view->backtotext = $text; $folder = new Application_Model_Folder($this->user, $id); /* all opted out subcribers from current account */ // echo "I am here".print_r($folder); if ($folder->isValid()) { // 1st see if the user tried to import subscribers if ($this->request->isPost()) { // See what action we are taking $actiontype = $this->request->getParam('actiontype'); if ($actiontype == 'upload') { // echo "<script type='text/javascript'>alert('UPLOAD')</script>"; // if ($this->user->isSuperAdmin() || $this->session->canImport) { // initialize the uploader $uploader = new Application_Model_Upload(); // get the action from post $upload = $this->request->getParam('upload'); $xls_template = trim($this->request->getParam('rbts_status')); // echo "<script type='text/javascript'>alert('Line 154')</script>"; if ($upload == 'Upload File') { // echo "<script type='text/javascript'>alert('Line 156')</script>"; $upload_path = '../application/imports/'; // set the upload directory $uploader->setUploadDir($upload_path); // echo "<script type='text/javascript'>alert('Line 160')</script>"; // give the valid file type extensions $uploader->setValidExt(array('csv')); // Give the filename some context $filename = $this->user->getId() . '-' . $id . '-' . time() . '.csv'; // do the upload if (($result = $uploader->uploadFile($filename)) === true) { $isTemplatewrong = false; // Now open the file and import the subscribers ini_set('auto_detect_line_endings', TRUE); if (($handle = fopen($upload_path . $filename, "rb")) !== false) { $tmpStatus = true; while (($subscriber = fgetcsv($handle, 0, "\n")) !== false) { if (trim($subscriber[0])) { $csvdata = explode(',', $subscriber[0]); $count_csv = count($csvdata); $phone = $folder->cleanPhone($csvdata[0]); if (strlen($phone) == 10) { $phone = '1' . $phone; $csvdata[0] = $phone; } if (strlen($phone) < 10) { continue; } $sbrStatus = $folder->check_status_ofsubcriber($phone); if (!$sbrStatus) { continue; } else { /* upload template type definition */ if ($xls_template === 'ph' && $count_csv == 1) { if ($folder->addSubscriber($csvdata[0]) === false) { $errors[] = $folder->getError(); } $isTemplatewrong = true; } if ($xls_template === 'phbd' && $count_csv == 2) { $bd = str_replace("_", "-", "{$csvdata['1']}"); if ($folder->addSubscriber($csvdata[0], "", "", $bd) === false) { $errors[] = $folder->getError(); } $isTemplatewrong = true; } if ($xls_template === 'pnbdfl' && $count_csv == 4) { $bd = str_replace("_", "-", "{$csvdata['3']}"); if ($folder->addSubscriber($csvdata[0], $csvdata[1], $csvdata[2], $bd) === false) { $errors[] = $folder->getError(); } $isTemplatewrong = true; } } } // usleep(10000); $datauploaded++; } // end of while loop // if template type is not the same with checked radio button if (!$isTemplatewrong) { $msg = '<script type="text/javascript">'; $msg .= ' $(function(){'; $msg .= ' csscody.alert("Incorrect template is selected!")});'; $msg .= '</script>'; echo $msg; $tmpStatus = false; } fclose($handle); if ($tmpStatus) { if (!empty($errors)) { $error = $errors; } else { $message = 'Subscribers imported!'; } } $act_id = $this->user->getId(); $email = $this->user->email; $business = $this->user->businessname; $phone = $this->user->office ? $this->user->office : $this->user->cell; $msg = "Data uploaded to the Textm system by:\n\nAccountid: " . $act_id . "\nEmail: " . $email . "\nBusinessname: " . $business . "\nPhone: " . $phone . "\nSubscribers imported: " . $datauploaded; $folder->sendEmail($email, "New data uploaded", $msg); } else { $error = 'The file uploaded but could not be imported. Please contact us.'; } } else { $error = $uploader->displayError(); } } // unset($syst_subscrbs); // } else { // $error = 'You do not have permission to carry out this operation'; // } } if ($actiontype == 'movenumber') { $newfolderid = $this->request->getParam('movedropdown'); $keywordDetails = $folder->getKeywordDetailsByFolderId($newfolderid); if (!empty($keywordDetails)) { $newkeywordid = $keywordDetails[0]['id']; } else { $newkeywordid = 0; } $subscriberidArray = $this->getRequest()->getParam('subscid'); foreach ($subscriberidArray as $subscriberid) { $moveradioid = 'moveradio' . $subscriberid; $moveORcopy = $this->request->getParam($moveradioid); if ($moveORcopy == 'copy') { $subscriberDetails = $folder->getSubscriberDetailsById($subscriberid); $newsubscriberid = $folder->copyPhoneNumber($newfolderid, $subscriberDetails[0]['phonenumber']); if ($newsubscriberid) { $message = "Phone number(s) copied sucessfully"; //$this->_redirector->gotoUrl('/folder/view/id/'.$newfolderid); } } elseif ($moveORcopy == 'move') { $subscriberDetails = $folder->getSubscriberDetailsById($subscriberid); if ($folder->numberExistsInNewFolder($subscriberDetails[0]['phonenumber'], $newfolderid)) { //if number already exists in the destination folder $existedNumberSubscriberId = $folder->numberExistsInNewFolder($subscriberDetails[0]['phonenumber'], $newfolderid); //id found then delete corresponding row from destination folder if ($folder->deleteNumberFromNewFolder($existedNumberSubscriberId)) { //now move number onto destination folder if ($folder->movePhoneNumber($subscriberid, $newfolderid, $newkeywordid)) { $message = "Phone number(s) moved sucessfully"; //$this->_redirector->gotoUrl('/folder/view/id/'.$newfolderid); } else { $error = 'An error occurred and the phone number has not been moved'; } } } else { //if number doesn't exist in the destination folder if ($folder->movePhoneNumber($subscriberid, $newfolderid, $newkeywordid)) { $message = "Phone number(s) moved sucessfully"; //$this->_redirector->gotoUrl('/folder/view/id/'.$newfolderid); } else { $error = 'An error occurred and the phone number has not been moved'; } } } } //echo "<pre>"; print_r($this->request); exit; } } if ($this->request->getParam('actiontype') == 'optout') { //if ($this->user->isSuperAdmin() || $this->session->canImport) { $subscriber = $this->request->getParam('subscriber'); if ($subscriber) { if ($folder->optOutSubscriberById($subscriber)) { $message = 'Subscriber opted out.'; } } //} /* else { $error = $error ? $error . "<br />" : ''; $error .= 'You do not have sufficient permission to opt out subscribers'; } */ } $foldername = $folder->name; $folderid = $folder->getId(); $subscribers = $folder->getSubscribersLatest(); //echo "<pre>"; print_r($subscribers); } else { $error = $folder->getError(); } // View variables $this->view->foldername = $foldername; $this->view->folderid = $folderid; $this->view->subscribers = $subscribers; $this->view->error = $error; $this->view->message = $message; $this->view->folderList = $folderList; $this->view->accountid = $this->user->getId(); $this->view->user = $this->user; //echo "<pre>"; print_r($this->view); //echo "I am here5555522";die; //exit; }