public function actionCreateZip() { $thread_id = base64_decode($_GET['id']); $data = TicketThread::model()->findByPk($thread_id); $files = unserialize($data->attachments); $path = Utils::getAttachmentpath(); $fileArr = array(); foreach ($files as $file) { $fileArr[] = $path . $file; } $zip = new ZipArchive(); $zipName = "comment_" . date("Y-m-d-H-i-s") . ".zip"; $fizip = $path . $zipName; if ($zip->open($fizip, ZipArchive::CREATE) === TRUE) { foreach ($fileArr as $fl) { if (file_exists($fl)) { $zip->addFile($fl, basename($fl)) or die("<p class='warning'>ERROR: Could not add file: " . $fl . "</p>"); } } } $resultArr = array(); $resultArr[] = $zip; $zip = $resultArr[0]; $size = filesize($zip->filename); if ($zip->filename) { $zip->close(); header("Content-Description: File Transfer"); header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=\"" . $zipName . "\""); header("Content-Transfer-Encoding: binary"); ob_end_flush(); flush(); readfile("{$path}{$zipName}"); unlink("{$path}{$zipName}"); } }
function actionEmailComments() { $template = Template::getTemplate('comment_mail_template'); $subject = $template->template_subject; $message = $template->template_content; $userdata['website_url'] = Utils::getBaseUrl(); $results = TicketThread::model()->findAllByAttributes(array(), array('condition' => 'send_mail = :send_mail', 'params' => array('send_mail' => 0))); foreach ($results as $users) { $ticket_id = $users->ticket_id; $comments = $users->descriptions; $files = unserialize($users->attachments); if (!empty($files)) { $doclink = '<a href="' . Yii::app()->createAbsoluteUrl('ticket/createZip/' . base64_encode($users->thread_id)) . '"><i class="fa fa-file"></i> Attachments #' . count($files) . '</a>'; } else { $doclink = 'No Attachments'; } $userdata['user_by'] = Users::model()->getUserName($users->user_id); $userdata['comment'] = $comments; $userdata['attachments'] = $doclink; $userdata['ticket_id'] = $ticket_id; $userdata['ticket_link'] = Utils::getBaseUrl() . "/ticket/view/" . base64_encode($ticket_id); $assignee = TicketAssign::model()->findAllByAttributes(array(), array('condition' => 'ticket_id = :ticket_id AND fwd_to !=:user_id AND status=1 ', 'params' => array('ticket_id' => $ticket_id, user_id => $users->user_id))); $assigneeby = TicketAssign::model()->findAllByAttributes(array(), array('condition' => 'ticket_id = :ticket_id AND fwd_by !=:user_id AND status=1 ', 'params' => array('ticket_id' => $ticket_id, user_id => $users->user_id), 'group' => "fwd_by")); // For Assignee mail foreach ($assignee as $user) { $userInfo = Users::model()->findByPk($user->fwd_to); $userdata['user_name'] = $userInfo->user_name; $subject = $this->replace($userdata, $subject); $message = $this->replace($userdata, $message); $this->SendMail($userInfo->user_email, $userInfo->user_name, $subject, $message); } // this is fowwarded by foreach ($assigneeby as $user) { $userInfo = Users::model()->findByPk($user->fwd_by); $userdata['user_name'] = $userInfo->user_name; $subject = $this->replace($userdata, $subject); $message = $this->replace($userdata, $message); $this->SendMail($userInfo->user_email, $userInfo->user_name, $subject, $message); } $model = TicketThread::model()->findByPk($users->thread_id); $model->send_mail = 1; $model->update(); } }