public function actionSavemessage() { $subject = Yii::app()->Ini->v('subject'); $message = Yii::app()->Ini->v('message'); $to_usertype = Yii::app()->Ini->v('to_usertype'); $from_id = Yii::app()->user->getId(); $from_user_type = Yii::app()->user->role; $to_id = Yii::app()->Ini->v('receiver_id'); $sent_date = date("Y-m-d H:i:s"); $messages = new Messages(); $messages->subject = $subject; $messages->message = $message; $messages->from_id = $from_id; $messages->to_id = $to_id; $messages->to_user_type = 'to_usertype'; $messages->from_user_type = $from_user_type; $messages->date_sent = $sent_date; $this->sendEmailNotification($subject, $message, $to_id, Yii::app()->name); if ($messages->save()) { $status = array('success' => true); } else { $status = array('success' => false, 'error_message' => print_r($messages->getErrors())); } $this->renderJSON($status); }
public function action_delete() { $id = $this->request->param('id'); DB::delete('address')->where('id', '=', $id)->execute(); Messages::save('Address was successfully deleted!', 'info'); $this->redirect('/address'); }
/** Receives the form submission from the new action and creates the new object. */ public function actionCreate() { // create a new message $messages = new Messages(); $name = $messages->generateNewName($this->request->getPost()); if (empty($name)) { $this->flashFail = 'The message cannot be blank'; $this->redirectTo('topics/new'); } $stamp = date("Y-m-d H:i:s", mktime()); $save['name'] = $this->userRow['name']; // create new topic $save['name'] = $this->request->getPost('name'); $save['created_at'] = $save['updated_at'] = $stamp; $save['created_by'] = $this->userRow['name']; $save['is_archived'] = 0; $topicId = $this->topics->save($save); // create new message... read by us $newId = $messages->save(array('topics_id' => $topicId, 'created_at' => $stamp, 'name' => $name, 'user' => $this->userRow['name'], 'read_by' => "!{$this->userRow['id']}!")); // create new mailer //$mailer = new Mailer(); // save the text $nodes = new Nodes(); $nodes->saveMessage(0, $this->request->getPost(0), $topicId, $newId, $this->userRow['name'], $mailer); // send email to all recipients //$users = new Users(); //foreach ($users->select('email')->findAll() as $user) $recipients[] = $user['email']; //$mailer->sendMessage($recipients, $newId, $topicId, $this->topics); // redirect to the new message $this->redirectTo("messages/show/{$topicId}/{$newId}"); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $result = $jobs->find(array('_id' => array('$in' => $ids))); $count = 0; foreach ($result as $job) { if (Arr::get($job, 'status') == Enums::STATUS_ARCHIVE || Arr::get($job, 'status') == Enums::STATUS_COMPLETE || Arr::get($job, 'status') == Enums::STATUS_PENDING) { if ($job['status'] == Enums::STATUS_PENDING) { $submissions = Database_Mongo::collection('submissions')->find(array('job_key' => $job['_id'], 'active' => 1))->count(); if ($submissions) { continue; } } $update = array('$set' => array('last_update' => time())); if (Arr::get($job, 'assigned')) { $update['$set']['status'] = Enums::STATUS_ALLOC; } else { $update['$unset']['status'] = 1; } $jobs->update(array('_id' => $job['_id']), $update); $count++; } } Messages::save($count . ' jobs were succesfully reset to initial state', 'success'); } $this->redirect('/search'); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $submissions = Database_Mongo::collection('submissions')->distinct('job_key', array('job_key' => array('$in' => $ids), 'active' => 1)); $ids = array_values(array_diff($ids, $submissions)); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => $ids))); print_r($result->explain()); $count = 0; foreach ($result as $job) { if (!in_array(Arr::get($job, 'status'), array(Enums::STATUS_ARCHIVE, Enums::STATUS_COMPLETE))) { $jobs->update(array('_id' => $job['_id']), array('$set' => array('last_update' => time(), 'status' => Enums::STATUS_COMPLETE))); $count++; } } Messages::save($count . ' jobs were succesfully completed', 'success'); } $this->redirect('/search'); }
public static function createMessage($fromUserId, $toUserId, $data) { $messages = new Messages(); $messages->from_user_id = $fromUserId; $messages->to_user_id = $toUserId; $messages->attributes = $data; return $messages->save(); }
public function action_delete() { $id = $this->request->param('id'); if (!Group::get(User::get($id, 'group_id'), 'is_admin')) { DB::delete('users')->where('id', '=', $id)->execute(); Messages::save('User successfully deleted!', 'info'); } $this->redirect('/security/users'); }
public function save() { $message = new Messages(); $message->sender_id = Yii::app()->user->id; $message->receiver_id = $this->receiver_id; $message->text = $this->text; $message->is_new = TRUE; $message->save(); }
public function action_delete() { if (!User::current('is_admin') && !Group::current('item_remove')) { throw new HTTP_Exception_403('Forbidden'); } $id = $this->request->param('id'); DB::delete('items')->where('id', '=', $id)->execute(); Messages::save('Item was successfully deleted!', 'info'); $this->redirect('/items'); }
public function action_delete() { $id = $this->request->param('id'); $users = DB::select('id')->from('users')->where('company_id', '=', $id)->limit(1)->execute()->get('id'); if (!$users) { DB::delete('companies')->where('id', '=', $id)->execute(); Messages::save('Company successfully deleted!', 'info'); } $this->redirect('/security/companies'); }
function render() { $message = new Messages($this->db); $message->key = 'Second message'; $message->message = 'This is the second message inserted from code'; $message->save(); $messages = new Messages($this->db); $msg = $messages->all()[0]; $this->f3->set('msg', $msg); $template = new Template(); echo $template->render('template.htm'); }
public function action_index() { $id = strval(Arr::get($_GET, 'id')); $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $id), array('data' => 1)); if (!$job) { throw new HTTP_Exception_404('Not found'); } $point = strval(Arr::get($_GET, 'point')); $archive = Database_Mongo::collection('archive')->findOne(array('_id' => new MongoId($point)), array('update_time' => 1)); if (!$archive) { throw new HTTP_Exception_404('Not found'); } $result = Database_Mongo::collection('archive')->find(array('job_key' => $id, 'update_time' => array('$gt' => $archive['update_time'])))->sort(array('update_time' => -1)); $ids = array(); $values = array(); foreach ($result as $item) { $ids[] = $item['_id']; foreach (Arr::get($item, 'data', array()) as $key => $data) { $job['data'][$key] = $values[$key] = $data['old_value']; } } foreach ($values as $key => $value) { if ($value) { $new['$set']['data.' . $key] = $value; } else { $new['$unset']['data.' . $key] = 1; } } if ($new) { $new['$set']['last_update'] = $archive['update_time']; } $submissions = array(); $result = Database_Mongo::collection('submissions')->find(array('job_key' => $id, 'process_time' => array('$gt' => $archive['update_time']))); foreach ($result as $item) { if (Arr::path($job, $item['key'], '') != $item['value']) { $submissions[] = $item['_id']; } } if ($new) { Database_Mongo::collection('submissions')->update(array('_id' => array('$in' => $submissions)), array('$unset' => array('process_time' => 1), '$set' => array('active' => 1))); Database_Mongo::collection('jobs')->update(array('_id' => $id), $new); Database_Mongo::collection('archive')->remove(array('_id' => array('$in' => $ids))); } $message = ''; if (count($ids)) { $message .= count($ids) . ' changes were removed. '; } if (count($submissions)) { $message .= count($submissions) . ' submissions were unapproved. '; } Messages::save('Ticket ' . $id . ' successfully rolled back to ' . date('d-m-Y H:i', $archive['update_time']) . '. ' . $message); die(json_encode(array('success' => true))); }
public function action_delete() { $id = $this->request->param('id'); if (!User::get($id, 'is_admin')) { Database::instance()->begin(); DB::delete('company_notifications')->where('user_id', '=', $id)->execute(); DB::delete('users')->where('id', '=', $id)->execute(); Database::instance()->commit(); Messages::save('User successfully deleted!', 'info'); } $this->redirect('/users'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Messages(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Messages'])) { $model->attributes = $_POST['Messages']; if ($model->save()) { $this->redirect(array('index')); } } $this->renderPartial('create', array('model' => $model)); }
public function action_delete() { $id = $this->request->param('id'); $users = DB::select('id')->from('users')->where('company_id', '=', $id)->limit(1)->execute()->get('id'); if (!$users) { Database::instance()->begin(); DB::delete('company_notifications')->where('company_id', '=', $id)->execute(); DB::delete('companies')->where('id', '=', $id)->execute(); Database::instance()->commit(); Messages::save('Company successfully deleted!', 'info'); } $this->redirect('/companies'); }
public function actionAnswer() { $model = new Messages(); if (isset($_POST['answer'])) { $model->from_uid = $_POST['from_uid']; $model->to_uid = $_POST['to_uid']; $model->title = $_POST['title']; $model->msg = CHtml::encode($_POST['answer']) . '<br />---------------------------------------<br /><i>' . $_POST['msg'] . '</i>'; if ($model->save()) { Messages::sendNotify($model->to_uid); $this->redirect(array('index')); } } $this->render('view', array('model' => $this->loadModel($_POST['from_uid']))); }
public function actionReply($id) { $model = new Messages(); $userDetails = $this->loadModel($id); $model->ReceiverId = $userDetails->sender->UserName; if (isset($_POST['Messages'])) { $model->attributes = $_POST['Messages']; $model->MessageId = $id; $model->SenderId = $userDetails->ReceiverId; $model->ReceiverId = $userDetails->SenderId; $model->Date = date('Y-m-d H:i:s'); if ($model->save()) { $this->redirect(array('message/index')); } } $this->render('reply', array('model' => $model)); }
public static function sendChatMessage($params = array()) { try { $q = new Messages(); $q->setMemberId($params['member_id']); $q->setSenderId($params['sender_id']); $q->setMessage($params['message']); $q->setIsRead($params['is_read']); $q->setDateRead(date('Y-m-d H:i:s')); $q->setPostingId($params['posting_id']); $q->setIsFriend($params['is_friend']); $q->save(); unset($q); return TRUE; } catch (Exception $e) { return array(FALSE, $e->getMessage()); } }
public function actionCompose() { $model = new Messages(); $this->performAjaxValidation($model); if (isset($_POST['Messages'])) { foreach ($_POST['Messages']['to_user_id'] as $user_id) { $model = new Messages(); $model->attributes = $_POST['Messages']; $model->to_user_id = $user_id; $model->save(); } $this->redirect(array('success')); } if (isset($_GET['to_user_id'])) { $model->to_user_id = $_GET['to_user_id']; } $this->render('compose', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Messages; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Messages'])) { $model->attributes=$_POST['Messages']; if($model->save()) $this->redirect(array('view','id'=>$model->id_record)); } $this->render('create',array( 'model'=>$model, )); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($id) { $model = new Messages(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); //var_dump(Yii::app()->request->getPost('Messages')); if (Yii::app()->request->getPost('Messages')) { $model->attributes = Yii::app()->request->getPost('Messages'); $model->receiver_id = $id; $model->sender_id = Yii::app()->user->id; $model->send_date = date('Y-m-d H:i:s'); //тупо но не нашел быстрого решения if ($model->validate()) { $model->save(); $this->redirect(array('messages/dialog', 'user' => $id)); } } $this->render('create', array('model' => $model, 'receiver' => $id)); }
public function action_index() { if (Session::instance()->get('user_id')) { $this->redirect('/'); } if ($_POST) { $login = Arr::get($_POST, 'login'); $passw = Arr::get($_POST, 'passw'); $id = DB::select('id')->from('users')->where('login', '=', $login)->and_where('passw', '=', Auth::instance()->hash($passw))->execute()->get('id'); if ($id) { DB::update('users')->set(array('last_seen' => time()))->where('id', '=', $id)->execute(); Session::instance()->set('user_id', $id); $this->redirect('/'); } else { Messages::save('Wrong login/password'); } } $view = View::factory("Login"); $this->response->body($view); }
public function addAction() { $this->initalize(); $msg = new Messages(); $success = $msg->save($this->request->getPost(), array('title', 'text')); if (!$success) { $this->_msgs['error'] = array(); foreach ($msg->getMessages() as $msgs) { $this->_msgs['error'] = $msgs; } $this->flash->error($this->_msgs['error']); } else { $this->flash->success('success adding message'); $this->_msgs['success'] = "Success adding Message"; } $this->view->form = new MessageForm(); $this->view->form->initalize(); if ($this->request->isPost()) { $this->view->form->clear(); $this->dispatcher->forward(array("controller" => "message", "action" => "list")); } }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $result = $jobs->find(array('_id' => array('$in' => $ids))); $count = 0; foreach ($result as $job) { if (Arr::get($job, 'status') != Enums::STATUS_PENDING && Arr::get($job, 'status') != Enums::STATUS_ARCHIVE) { $jobs->update(array('_id' => $job['_id']), array('$set' => array('last_update' => time(), 'status' => Enums::STATUS_ARCHIVE))); $count++; } } Messages::save($count . ' jobs were succesfully archived', 'success'); } $this->redirect('/search'); }
/** * [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved. * The contents of this file are subject to the License; you may not use this file except in compliance with the License. * * @version $Revision: 2048 $ */ if (!defined('IN_PHPB2B')) { exit('Not A Valid Entry Point'); } uses("message"); $companymessage = new Messages(); if (isset($_POST['companyid']) && !empty($_POST['feed']) && !empty($pb_user)) { $vals = $_POST['feed']; $vals['created'] = $time_stamp; $vals['status'] = 0; $vals['from_member_id'] = $pb_user['pb_userid']; $vals['cache_from_username'] = $pb_user['pb_username']; if (empty($member->info)) { $vals['to_member_id'] = $administrator_id; $vals['cache_to_username'] = $pdb->GetOne("SELECT username FROM {$tb_prefix}members WHERE id=" . $administrator_id); } else { $vals['to_member_id'] = $member->info['id']; $vals['cache_to_username'] = $member->info['username']; } $vals['title'] = L("pms_from_space", "tpl"); if ($companymessage->save($vals)) { $smarty->flash('feedback_already_submit', null, 0); } } $space->render("feedback");
public function action_index() { $id = intval($this->request->param('id')); $attachment = DB::select()->from('attachments')->where('id', '=', $id)->execute()->current(); if (!$attachment) { throw new HTTP_Exception_404('Not found'); } if (Arr::get($attachment, 'uploaded')) { throw new HTTP_Exception_403('Forbidden'); } $job_id = Arr::get($attachment, 'job_id'); $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($job_id))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array((int) User::current('company_id'), Arr::get($job, 'companies', array()), true) && !in_array((int) User::current('company_id'), Arr::get($job, 'ex', array()), true)) { throw new HTTP_Exception_403('Forbidden'); } if ($_FILES) { try { $file = Arr::get($_FILES, 'attachment', array()); $file['name'] = trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-\\.]/i', '-', Arr::get($file, 'name', ''))), '-'); preg_match_all("/([0-9]+)/", Arr::get($_SERVER, 'HTTP_CONTENT_RANGE', ''), $matches); $range = Arr::get($matches, 0); $size = Arr::get($range, 2, filesize($file['tmp_name'])); if (!is_uploaded_file($file['tmp_name'])) { die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size, 'error' => 'Error!')))); } $src = fopen($file['tmp_name'], 'r'); $dest = fopen(DOCROOT . 'storage/' . $id, 'c'); fseek($dest, Arr::get($range, 0, 0)); $buf = fread($src, $size); fwrite($dest, $buf); fclose($dest); fclose($src); unlink($file['tmp_name']); if (!$range || Arr::get($range, 1) + 1 == Arr::get($range, 2)) { $data = array('filename' => $file['name'], 'mime' => $file['type'], 'uploaded' => time()); if ($attachment['filename']) { $data['filename'] = $attachment['filename']; $pos = strrpos($file['name'], '.'); if ($pos !== false) { $data['filename'] .= substr($file['name'], $pos); } } else { $data['filename'] = ($attachment['folder'] == 'Other' ? $attachment['title'] : '') . $file['name']; } $data['filename'] = str_replace('%NUM%', $attachment['numbering'], $data['filename']); Database::instance()->begin(); DB::update('attachments')->set($data)->where('id', '=', $id)->execute(); $filename = $data['filename']; $data = array('user_id' => User::current('id'), 'job_id' => $attachment['job_id'], 'uploaded' => $data['uploaded'], 'location' => $attachment['location'], 'filename' => $attachment['folder'] . ' / ' . $attachment['fda_id'] . ' / ' . $attachment['address'] . ' / ' . $data['filename'], 'action' => 1); DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute(); Database::instance()->commit(); Database_Mongo::collection('jobs')->update(array('_id' => $attachment['job_id']), array('$unset' => array('downloaded' => 1), '$set' => array('last_update' => time()))); Messages::save("File " . $file['name'] . ' was successfully uploaded!', 'success'); $is_image = preg_match('/^image\\/.*$/i', $file['type']); die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size, 'content' => '<table><tr>' . (Group::current('allow_assign') ? '<td><a href="' . URL::base() . 'search/view/' . $id . '?delete=' . $id . '" confirm="Do you really want to delete this attachment? This action can\'t be undone!!!" class="text-danger glyphicon glyphicon-remove remove-link"></a></td>' : '') . '<td><div class="td-image-center">' . ($is_image ? '<img src="' . URL::base() . 'download/thumb/' . $id . '" alt="Thumbnail" />' : '<img src="http://stdicon.com/' . $file['type'] . '?size=96&default=http://stdicon.com/text" />') . '</div></td><td><a data-id="' . $id . '" class="' . ($is_image && $attachment['folder'] != 'Signatures' ? 'image-attachments' : '') . '" href="' . URL::base() . 'download/attachment/' . $id . '">' . HTML::chars($attachment['folder']) . '<br/>' . HTML::chars($attachment['fda_id']) . '<br/>' . HTML::chars($attachment['address']) . '<br/>' . HTML::chars($filename) . '</a><br/> - Uploaded ' . date('d-m-Y H:i', $data['uploaded']) . ' by ' . User::current('login') . '</td></tr></table>', 'message' => Messages::render())))); } } catch (Exception $e) { die($e->getMessage()); } die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size)))); } $view = View::factory("Jobs/UploadFile"); $this->response->body($view); }
public function actionSendMessage($id) { $model = new Messages(); $user = Profile::model()->findByAttributes(array('UserId' => $id)); if (isset($_POST['Messages'])) { $model->attributes = $_POST['Messages']; $model->SenderId = Yii::app()->user->getId(); $model->Date = date('Y-m-d H:i:s'); if ($model->save()) { echo CHtml::script("window.parent.\$('#cboxClose').colorbox.close();"); } } $this->renderPartial('message', array('model' => $model, 'user' => $user), false, true); }
public function actionNewmessages() { $this->layout = 'empty'; $model = new Messages(); // uncomment the following code to enable ajax-based validation if (isset($_POST['ajax']) && $_POST['ajax'] === 'messages-messages-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['Messages'])) { $usersId = $_POST['Messages']['user_id']; $usersId = explode(',', $usersId); // if ($model->validate()) { foreach ($usersId as $i) { $u = explode('(', $i); if ($u[0] != " ") { $u = explode('(', $i); $u1 = explode(')', $u[1]); $userTo = User::model()->find('email=:eId', array(':eId' => $u1[0])); if ($userTo) { $newModel = new Messages(); $newModel->sender_id = Yii::app()->user->userId; $newModel->user_id = $userTo['id']; $newModel->subject = $_POST['Messages']['subject']; $newModel->message = $_POST['Messages']['message']; $newModel->is_read = 0; $newModel->save(); $Id = Yii::app()->db->getLastInsertId(); $chat = new MessageChat(); $chat->message_id = $Id; $chat->user_id = $userTo['id']; $chat->sender_id = Yii::app()->user->userId; $chat->message = $_POST['Messages']['message']; $chat->save(); } } } Yii::app()->user->setFlash('success', "Your message has been sent."); // echo '<script type="text/javascript">window.top.location.href = "' . Yii::app()->baseUrl . '/index.php/user/inbux"; </script>'; $this->redirect(Yii::app()->baseUrl . '/index.php/user/inbux'); } $this->render('newmessage', array('model' => $model)); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { if (Yii::app()->user->isGuest) { $this->layout = 'login'; $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { // echo "tetste"; exit(); $date = date('Y-m-d H:i:s'); // print_r($_POST['LoginForm']);exit(); $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $loginUserID = Yii::app()->user->getId(); Users::model()->updateByPk($loginUserID, array('LoginStatus' => 1, 'LastLoginDate' => $date)); /* $this->redirect(array('site/index')); */ $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); } else { $loginUserId = Yii::app()->user->getId(); $message = new Messages(); $userList = array(); $idLilst = array(); $location = ''; $genVal = ''; $minAge = 18; $maxAge = 30; $pageCount = 20; $criteria = new CDbCriteria(); $condition = "Status=1 AND SearchStatus=1 AND Objid <> {$loginUserId}"; if (isset($_POST['Messages'])) { $message->attributes = $_POST['Messages']; $message->SenderId = $loginUserId; $message->Date = date('Y-m-d H:i:s'); if ($message->save()) { $this->redirect(array('site/index')); } } if (isset($_GET['Find'])) { $minAge = $_GET['MinAge']; $maxAge = $_GET['MaxAge']; $minAge1 = $_GET['MinAge'] - 1; $maxAge1 = $_GET['MaxAge'] + 1; $toDate = date('Y-m-d', strtotime('-' . $minAge1 . ' years')); $fromDate = date('Y-m-d', strtotime('-' . $maxAge1 . ' years')); $condition .= " AND DateOfBirth BETWEEN '" . $fromDate . "' AND '" . $toDate . "'"; if (isset($_GET['searchAttList'])) { $idLilst = $_GET['searchAttList']; $attributes = implode(',', $idLilst); $criteria2 = new CDbCriteria(); $criteria2->condition = "AttributeValueId IN(" . $attributes . ") GROUP BY AttributeId"; $total = UserOptions::model()->findAll($criteria2); $count = count($total); $count = $count - 1; $criteria1 = new CDbCriteria(array('having' => 'COUNT(ObjId) > ' . $count)); $criteria1->condition = "AttributeValueId IN(" . $attributes . ")"; $criteria1->group = "UserId"; $userData = UserOptions::model()->findAll($criteria1); if ($userData) { foreach ($userData as $data) { $userList[] = $data->UserId; } $condition .= " AND Objid IN (" . implode(',', $userList) . ")"; } else { $condition .= " AND Objid IN (0)"; } } if (isset($_GET['Gender']) && $_GET['Gender']) { $genVal = $_GET['Gender']; if ($_GET['Gender'] == 1) { $condition .= " AND Gender=0"; } else { if ($_GET['Gender'] == 2) { $condition .= " AND Gender=1"; } } } if (isset($_GET['Location']) && $_GET['Location']) { $location = $_GET['Location']; $condition .= " AND CityOrPostal LIKE '%" . $location . "%'"; } if (isset($_GET['postsPerPage']) && $_GET['postsPerPage']) { $pageCount = $_GET['postsPerPage']; } } if (isset($_GET['type']) && $_GET['type'] == 'online') { $expDate = date('Y-m-d H:i:s', strtotime('-2 minutes')); $condition .= " AND LoginStatus=1 AND LastActivity >'" . $expDate . "'"; } if (isset($_GET['type']) && $_GET['type'] == 'new') { $now = date('Y-m-d H:i:s', strtotime('last month')); $condition .= ' AND CreatedDate > "' . $now . '"'; } $criteria->condition = $condition; $count = Profile::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = $pageCount; $pages->applyLimit($criteria); $model = Profile::model()->findAll($criteria); $this->render('list', array('models' => $model, 'location' => $location, 'idLilst' => $idLilst, 'gender' => $genVal, 'minAge' => $minAge, 'maxAge' => $maxAge, 'pages' => $pages, 'pageCount' => $pageCount, 'message' => $message)); } }
public function action_fill() { $id = Arr::get($_GET, 'id'); if ($id) { $filters = array('_id' => new MongoId($id)); if (!Group::current('show_all_jobs')) { $filters['company'] = User::current('company_id'); } $form_data = Database_Mongo::collection('forms-data')->findOne($filters); $form_id = $form_data['form_id']; } else { $data = explode('/', Arr::get($_GET, 'form', '')); $form_id = $data[0]; $form_data = array(); } $form = Database_Mongo::collection('forms')->findOne(array('_id' => new MongoId($form_id))); if (!$form) { throw new HTTP_Exception_404('Not found'); } if (!$form_data) { $form_data['form_id'] = $form_id; $form_data['data'] = array(); foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { if (Arr::get($input, 'name')) { $form_data['data'][$input['name']] = ''; } } } } } } switch ($form['type']) { case Form::FORM_TYPE_COMMON: break; case Form::FORM_TYPE_TICKET: if (isset($form_data['job'])) { $job_id = $form_data['job']; } else { $job_id = $data[1]; $form_data['job'] = $job_id; } $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($job_id))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array(User::current('company_id'), array_merge(Arr::get($job, 'companies', array()), Arr::get($job, 'ex', array())))) { throw new HTTP_Exception_404('Not found'); } foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { switch (Arr::get($input, 'type')) { case 'ticket': $form['data'][$key]['data'][$row][$cell]['type'] = 'label'; $form['data'][$key]['data'][$row][$cell]['placeholder'] = Arr::get($input, 'value') ? Columns::output(Arr::path($job, 'data.' . $input['value']), Columns::get_type($input['value'])) : $job['_id']; $form['data'][$key]['data'][$row][$cell]['destination'] = Arr::get($input, 'destination'); unset($form['data'][$key]['data'][$row][$cell]['value']); break; case 'timestamp': $form['data'][$key]['data'][$row][$cell] = array('type' => 'timestamp', 'placeholder' => Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : '', 'destination' => Arr::get($input, 'destination')); break; case 'revision': $form['data'][$key]['data'][$row][$cell] = array('type' => 'revision', 'placeholder' => Arr::get($form_data, 'revision', 1), 'destination' => Arr::get($input, 'destination')); break; } } } } } break; } if (isset($_GET['load']) || isset($_GET['print']) || $_POST) { header('Content-type: application/json'); if (isset($form_data['job'])) { $job = Database_Mongo::collection('jobs')->findOne(array('_id' => is_array($form_data['job']) ? array('$in' => $form_data['job']) : $form_data['job'])); } if ($_POST || isset($_GET['print'])) { if (isset($_GET['print'])) { $columns = DB::select('id')->from('report_columns')->where('report_id', '=', Arr::get($form, 'report'))->execute()->as_array('id', 'id'); $report = array(); $colors = array(); $update = array(); $hide = array(); foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { if (Arr::get($table, 'data-related-option') && Arr::get($table, 'data-related-value') != Arr::get($form_data['data'], $table['data-related-option'])) { $hide[] = $key; } else { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { switch (Arr::get($input, 'type')) { case 'revision': $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'revision', 1); break; case 'timestamp': $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : ''; break; } if (Arr::get($input, 'name')) { $form['data'][$key]['data'][$row][$cell]['value'] = $input['value'] = Arr::path($form_data, array('data', $input['name']), ''); } if (Arr::get($input, 'destination') && isset($columns[$input['destination']])) { if (isset($input['colors'])) { try { $list = array_combine(explode(',', $input['options']), explode(',', $input['colors'])); $color = Arr::get($list, $input['value']); } catch (Exception $e) { $color = false; } if ($color) { $colors[$input['destination']] = $color; } } $report[$input['destination']] = Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder'); } if (Arr::get($input, 'bindValue')) { $bind = explode(',', $input['bindValue']); foreach ($bind as $target) { $update[$target] = array('value' => Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder'), 'type' => 'replace'); } } } } } } } foreach ($hide as $key) { unset($form['data'][$key]); } $view = View::factory('Forms/PDF')->bind('name', $form['name'])->bind('form', $form['data'])->set('attachments', Arr::get($form_data, 'attachments', array())); require_once APPPATH . 'mpdf/mpdf.php'; $pdf = new mPDF('UTF-8', 'A4'); $pdf->ignore_invalid_utf8 = true; $pdf->shrink_tables_to_fit = 1; $pdf->keep_table_proportions = true; $pdf->WriteHTML($view); $content = $pdf->Output('', 'S'); $name = trim(preg_replace('/-{2,}/', '-', preg_replace('/[^a-z0-9]/i', '-', $form['name'])), '-'); switch ($form['type']) { case Form::FORM_TYPE_COMMON: $jobs = array(0); break; case Form::FORM_TYPE_TICKET: $jobs = array($job['_id']); break; } $company = DB::select('name')->from('companies')->where('id', '=', $form_data['company'])->execute()->get('name'); $uploaded = time(); $submissions = array(); $submission = array('user_id' => User::current('id'), 'active' => 1, 'update_time' => $uploaded); foreach ($jobs as $job) { if ($job) { $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $job), array('data' => 1)); $new = array(); $archive = array(); foreach ($update as $key => $value) { if ($value['type'] == 'append') { switch (Columns::get_type($key)) { case 'int': case 'number': case 'float': $value = Arr::path($job, 'data.' . $key, 0) + $value['value']; break; default: $value = Arr::path($job, 'data.' . $key, '') . "\n" . $value['value']; break; } } else { $value = $value['value']; } if ($value) { $value = Columns::parse($value, Columns::get_type($key)); } if (Group::current('allow_assign') || Columns::get_direct($key)) { if ($value) { $new['$set']['data.' . $key] = $value; } else { $new['$unset']['data.' . $key] = 1; } if (!Group::current('allow_assign')) { $submission['job_key'] = $job['_id']; $submission['key'] = 'data.' . $key; $submission['value'] = $value; $submission['active'] = -1; $submission['process_time'] = $uploaded; Database_Mongo::collection('submissions')->insert($submission); unset($submission['process_time']); unset($submission['_id']); } $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key, ''), 'new_value' => $value); } else { $new['$set']['status'] = Enums::STATUS_PENDING; $submissions[$job['_id']][$key] = $value; } } if ($new) { $new['$set']['last_update'] = $uploaded; Database_Mongo::collection('jobs')->update(array('_id' => $job['_id']), $new); if ($archive) { $archive['fields'] = array_keys($archive['data']); $archive['job_key'] = $job['_id']; $archive['user_id'] = User::current('id'); $archive['update_time'] = $uploaded; $archive['update_type'] = 2; $archive['filename'] = 'MANUAL'; Database_Mongo::collection('archive')->insert($archive); } } } $filename = $name . ' (' . $company . ') -' . date('dmY-His') . '.pdf'; $data = array('filename' => $filename, 'mime' => 'application/pdf', 'uploaded' => $uploaded, 'user_id' => $form_data['user_id'], 'job_id' => $job ? $job['_id'] : 0, 'folder' => 'Reports', 'fda_id' => $job ? Arr::path($job, 'data.14') : 'Unattached', 'address' => $job ? trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-]/i', '-', Arr::path($job, 'data.8'))), '-') : 'Unattached', 'title' => ''); Database::instance()->begin(); $result = DB::insert('attachments', array_keys($data))->values(array_values($data))->execute(); $image_id = Arr::get($result, 0); if ($image_id && file_put_contents(DOCROOT . 'storage/' . $image_id, $content)) { unset($data['mime']); $data = array('filename' => 'Reports / ' . ($job ? Arr::path($job, 'data.14') : 'Unattached') . ' / ' . ($job ? $data['address'] : 'Unattached') . ' / ' . $data['filename'], 'uploaded' => $uploaded, 'user_id' => User::current('id'), 'job_id' => $job ? $job['_id'] : 0, 'action' => 1); DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute(); Database::instance()->commit(); Database_Mongo::collection('forms-data')->remove(array('_id' => new MongoId($id))); if ($report) { $data = $report; $report = array('report_id' => intval(Arr::get($form, 'report')), 'user_id' => $form_data['user_id'], 'company' => $form_data['company'], 'attachment_id' => $image_id, 'attachment' => $filename, 'uploaded' => $uploaded, 'colors' => $colors); if (Arr::get($form_data, 'attachments')) { $report['attachments'] = $form_data['attachments']; } if (isset($form_data['geo'])) { $report['geo'] = $form_data['geo']; } $columns = DB::select('id', 'type')->from('report_columns')->where('report_id', '=', $report['report_id'])->execute()->as_array('id', 'type'); foreach ($columns as $key => $value) { $report[$key] = Arr::get($data, $key) ? Columns::parse($data[$key], $value) : ''; } Database_Mongo::collection('reports')->insert($report); } } else { Messages::save('Error occurred during report processing... Please try again later'); } } foreach ($submissions as $job_key => $values) { foreach ($values as $key => $value) { $submission['job_key'] = $job_key; $submission['key'] = 'data.' . $key; $submission['value'] = $value; $submission['active'] = 1; Database_Mongo::collection('submissions')->insert($submission); unset($submission['_id']); } } $target = 'attachments'; } else { $target = 'forms'; $fl = false; foreach ($form_data['data'] as $key => $value) { if (Arr::get($_POST, $key) != $value) { $form_data['data'][$key] = Arr::get($_POST, $key); $fl = true; } } if ($fl) { $form_data['last_update'] = time(); if (Arr::get($form, 'geo')) { $form_data['geo'] = Arr::get($_POST, 'geo'); } } if ($id) { if ($fl) { $form_data['revision']++; } Database_Mongo::collection('forms-data')->update(array('_id' => new MongoId($id)), $form_data); } else { $form_data['created'] = time(); $form_data['user_id'] = User::current('id'); $form_data['company'] = User::current('company_id'); $form_data['revision'] = 1; $form_data['last_update'] = time(); Database_Mongo::collection('forms-data')->insert($form_data); $id = strval($form_data['_id']); } } header('Content-type: application/json'); switch ($form['type']) { case Form::FORM_TYPE_TICKET: $url = URL::base() . 'search/view/' . $form_data['job'] . '#' . $target; break; case Form::FORM_TYPE_COMMON: $url = URL::base() . 'form/unattached'; break; } die(json_encode(array('success' => true, 'id' => $id, 'url' => $url))); } foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { if (Arr::get($input, 'name')) { $form['data'][$key]['data'][$row][$cell]['value'] = Arr::get($form_data['data'], $input['name']); } } } } } die(json_encode(array('form' => $form['data'], 'attachments' => Arr::get($form_data, 'attachments')))); } $view = View::factory('Forms/Form')->set('form_id', $form_id)->set('id', $id)->set('allow_geo', Arr::get($form, 'geo'))->set('allow_attachment', Arr::get($form, 'attachment'))->set('name', $form['name']); $this->response->body($view); }