public function actionAdd() { $model = new TicketsForm(); $ticketModel = new Tickets(); if (isset($_POST[CHtml::modelName($model)])) { $model->setAttributes($_POST[CHtml::modelName($model)]); if ($model->validate()) { $transaction = db()->beginTransaction(); try { // Сохраняю тикет $ticket = new Tickets(); $ticket->category_id = $model->category_id; $ticket->priority = $model->priority; $ticket->date_incident = $model->date_incident; $ticket->char_name = $model->char_name; $ticket->title = $model->title; $ticket->new_message_for_admin = 1; $ticket->gs_id = user()->getGsId(); $ticket->status = Tickets::STATUS_ON; $ticket->save(FALSE); $ticketId = db()->getLastInsertID(); // Сохраняю переписку для тикета $ticketAnswer = new TicketsAnswers(); $ticketAnswer->ticket_id = $ticketId; $ticketAnswer->text = $model->text; $ticketAnswer->save(FALSE); // Логирую действие юзера if (app()->params['user_actions_log']) { $log = new UserActionsLog(); $log->user_id = user()->getId(); $log->action_id = UserActionsLog::ACTION_CREATE_TICKET; $log->save(FALSE); } notify()->adminNoticeTicketAdd(array('user' => user()->getUser(), 'ticket' => $ticket)); user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Тикет создан.')); $transaction->commit(); $this->redirect(array('index')); } catch (Exception $e) { $transaction->rollback(); user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__ . ' ' . __LINE__); } $this->refresh(); } } $this->render('//cabinet/tickets/add', array('model' => $model, 'ticketModel' => $ticketModel)); }
public function convertToTicket($thread_id, $msg_id, $user, $subject, $message, $department_id, $company_id) { $ticket = new Tickets(); $ticket->thread_id = $thread_id; $ticket->customer_id = $user->id; $ticket->priority = Tickets::PRIORITY_MEDIUM; $ticket->company_id = $company_id; $ticket->department_id = $department_id; $ticket->subject = $subject; $ticket->description = $message; $ticket->status = Tickets::TICKET_NEW; $ticket->requested_on = \Carbon\Carbon::now(); $ticket->save(); $ticket_attachment = new TicketAttachments(); $ticket_attachment->thread_id = $thread_id; $ticket_attachment->message_id = $msg_id; $ticket_attachment->has_attachment = Input::hasFile('attachment'); $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : ''; $ticket_attachment->save(); $customer = User::find($ticket->customer_id); $ticketMailer = new \KodeInfo\Mailers\TicketsMailer(); $mailer_extra = Tickets::getCreatedFields(false, $ticket->id, $msg_id); $ticketMailer->created($customer->email, $customer->name, $mailer_extra); }
/** * Create a new ticket */ public function actionCreate() { // Initiate Model $model = new Tickets(); $model->assignedtoid = ''; if (isset($_POST['Tickets'])) { $model->setScenario('ticketupdate'); $model->setAttributes($_POST['Tickets']); // Was the form submitted? if (isset($_POST['submit'])) { // Bug: assigntoid cannot be null if (!$model->assignedtoid) { $model->assignedtoid = 0; } if ($model->save()) { $comment = new TicketComments(); $comment->content = $model->content; $comment->ticketid = $model->id; $comment->firstcomment = 1; $comment->save(); // Update ticket id $model->lastcommentid = $comment->id; $model->update(); // Mark flash and redirect Functions::setFlash(Yii::t('tickets', 'Tickets: Ticket Created.')); $this->redirect(array('/tickets')); } } } // make sure we display the name of the if (isset($_POST['Tickets']['assignedtoid'])) { $model->assignedtoid = $_POST['Tickets']['assignedtoid']; } // Add title $title = Yii::t('tickets', 'Creating A Ticket'); $this->pageTitle[] = $title; $this->render('create', array('model' => $model, 'title' => $title)); }
public function store() { $v = Validator::make(["name" => Input::get('name'), "email" => Input::get('email'), "priority" => Input::get('priority'), "company" => Input::get('company'), "department" => Input::get('department'), "attachment" => Input::get('attachment'), "subject" => Input::get('subject'), "description" => Input::get('description')], ["name" => 'required', "email" => 'required|email', "priority" => 'required', "company" => 'required', "department" => 'required', "description" => 'required', "attachment" => 'mimes:rar,zip|size:10000', "subject" => 'required']); if ($v->passes()) { $company_customer_ids = CompanyCustomers::where('company_id', Input::get('company'))->lists('customer_id'); if (sizeof($company_customer_ids) > 0) { $user = User::where('email', Input::get('email'))->first(); } else { $user = null; } if (!empty($user) && !is_null($user)) { $user = User::where('email', Input::get('email'))->first(); if (!empty($user)) { $company_customer = new CompanyCustomers(); $company_customer->company_id = Input::get('company'); $company_customer->customer_id = $user->id; $company_customer->save(); } } else { $password = Str::random(); $userManager = new \KodeInfo\UserManagement\UserManagement(); $user = $userManager->createUser(["name" => Input::get('name'), "email" => Input::get('email'), "password" => $password, "password_confirmation" => $password], 'customer', false); $user->avatar = "/assets/img/default-avatar.jpg"; $user->save(); $company_customer = new CompanyCustomers(); $company_customer->company_id = Input::get('company'); $company_customer->customer_id = $user->id; $company_customer->save(); } $repo = new KodeInfo\Repo\MessageRepo(); $thread = $repo->createNewThread($user->id, Input::get("description"), true); $ticket = new Tickets(); $ticket->thread_id = $thread['thread_id']; $ticket->customer_id = $user->id; $ticket->priority = Input::get("priority"); $ticket->company_id = Input::get("company"); $ticket->department_id = Input::get("department"); $ticket->subject = Input::get("subject"); $ticket->description = Input::get("description"); $ticket->status = Tickets::TICKET_NEW; $ticket->requested_on = \Carbon\Carbon::now(); $ticket->save(); $ticket_attachment = new TicketAttachments(); $ticket_attachment->thread_id = $thread['thread_id']; $ticket_attachment->message_id = $thread['msg_id']; $ticket_attachment->has_attachment = Input::hasFile('attachment'); $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : ''; $ticket_attachment->save(); $country = DB::table('countries')->where('countryCode', Input::get('country'))->first(); $geo_info = new ThreadGeoInfo(); $geo_info->thread_id = $thread['thread_id']; $geo_info->ip_address = Input::get('ip'); $geo_info->country_code = Input::get('country'); $geo_info->country = !empty($country) ? $country->countryName : ""; $geo_info->provider = Input::get('provider'); $geo_info->current_page = ""; $geo_info->all_pages = ""; $geo_info->save(); $customer = User::find($ticket->customer_id); $mailer_extra = ['ticket' => $ticket, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path]; $this->ticketMailer->created($customer->email, $customer->name, $mailer_extra); RecentActivities::createActivity("New Ticket created by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name); Session::flash('success_msg', trans('msgs.ticket_created_success')); return Redirect::to('/tickets/all'); } else { Session::flash('error_msg', Utils::buildMessages($v->messages()->all())); return Redirect::back()->withInput(Input::except('attachment')); } }
/** * Save the ticket * * @param integer $id * @param integer $customer * @param string $subject * @param string $description * @param integer $category * @param integer $status * @param integer $domain * @return Boolean or integer */ public static function saveIt($id = null, $customer, $subject, $description, $category, $status = null, $domain = null) { $translator = Shineisp_Registry::getInstance()->Zend_Translate; $isUpdate = false; if (is_numeric($id)) { $ticket = self::find($id); $isUpdate = true; } else { $ticket = new Tickets(); } $operatorId = Settings::findbyParam('tickets_operator', 'admin', Isp::getActiveISPID()); if (!is_numeric($operatorId)) { $operator = AdminUser::getFirstAdminUser(); } else { $operator = AdminUser::getAllInfo($operatorId); } if (is_numeric($customer)) { $ticket->subject = !empty($subject) ? $subject : $translator->translate('Generic Issue'); $ticket->description = !empty($description) ? $description : null; $ticket->category_id = !empty($category) ? $category : null; $ticket->customer_id = $customer; $ticket->user_id = $operator['user_id']; $ticket->date_open = date('Y-m-d H:i:s'); $ticket->date_updated = date('Y-m-d H:i:s'); $ticket->domain_id = is_numeric($domain) && $domain > 0 ? $domain : NULL; $ticket->status_id = !empty($status) ? $status : Statuses::id("expectingreply", "tickets"); // Expecting a reply as default $ticket->save(); $id = $ticket->getIncremented(); // Save the upload file $attachment = self::UploadDocument($id, $customer); // Check if the request is an update if ($isUpdate == false) { // Create for the first time the fast link Fastlinks::CreateFastlink('tickets', 'edit', json_encode(array('id' => $id)), 'tickets', $id, $customer); // Send ticket by email self::send($id, true, $attachment); } return $id; } return false; }