public function destroy($id)
 {
     $delete = Client::find($id);
     $delete->delete();
     $data = array('clients' => Client::orderBy('id', 'desc')->get(), 'refresh' => true);
     return View::make('clients.table', $data);
 }
 public function deleteUser($id)
 {
     $admin = Client::find($id);
     Client::destroy($id);
     Session::flash('flash_msg', "L'administrateur " . $admin->loginClient . " a bien été supprimé.");
     Session::flash('flash_type', "warning");
     return Redirect::to('/admin/users');
 }
 public function deleteUtilisateur($id)
 {
     $utilisateur = Client::find($id);
     Client::destroy($id);
     Session::flash('flash_msg', "L'utilisateur " . $utilisateur->prenomClient . " " . $utilisateur->nomClient . " a bien été supprimé.");
     Session::flash('flash_type', "warning");
     return Redirect::to('/admin/utilisateurs');
 }
 function __construct()
 {
     parent::__construct();
     $this->view_data['core_settings'] = Setting::first();
     if ($this->input->cookie('language') != "") {
         $language = $this->input->cookie('language');
     } else {
         if (isset($this->view_data['language'])) {
             $language = $this->view_data['language'];
         } else {
             if (!empty($this->view_data['core_settings']->language)) {
                 $language = $this->view_data['core_settings']->language;
             } else {
                 $language = "english";
             }
         }
     }
     $this->lang->load('application', $language);
     $this->lang->load('messages', $language);
     $this->lang->load('event', $language);
     $this->user = $this->session->userdata('user_id') ? User::find_by_id($this->session->userdata('user_id')) : FALSE;
     $this->client = $this->session->userdata('client_id') ? Client::find_by_id($this->session->userdata('client_id')) : FALSE;
     if ($this->client) {
         $this->theme_view = 'application_client';
     }
     $this->view_data['datetime'] = date('Y-m-d H:i', time());
     $this->view_data['sticky'] = Project::all(array('conditions' => 'sticky = 1'));
     $this->view_data['quotations_new'] = Quote::find_by_sql("select count(id) as amount from quotations where status='New'");
     if ($this->user || $this->client) {
         $access = $this->user ? $this->user->access : $this->client->access;
         $access = explode(",", $access);
         if ($this->user) {
             $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'main')));
             $this->view_data['widgets'] = Module::find('all', array('conditions' => array('id in (?) AND type = ?', $access, 'widget')));
         } else {
             $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'client')));
         }
         if ($this->user) {
             $update = User::find($this->user->id);
         } else {
             $update = Client::find($this->client->id);
         }
         $update->last_active = time();
         $update->save();
         if ($this->user) {
             $this->view_data['user_online'] = User::all(array('conditions' => array('last_active+(30 * 60) > ? AND status = ?', time(), "active")));
             $this->view_data['client_online'] = Client::all(array('conditions' => array('last_active+(30 * 60) > ? AND inactive = ?', time(), "0")));
         }
         $email = $this->user ? 'u' . $this->user->id : 'c' . $this->client->id;
         $this->view_data['messages_new'] = Privatemessage::find_by_sql("select count(id) as amount from privatemessages where `status`='New' AND recipient = '" . $email . "'");
         $this->view_data['tickets_new'] = Ticket::find_by_sql("select count(id) as amount from tickets where `status`='New'");
     }
     /*$this->load->database();
     		$sql = "select * FROM templates WHERE type='notes'";
     		$query = $this->db->query($sql); */
     $this->view_data["note_templates"] = "";
     //$query->result();
 }
Example #5
0
 public function indexAction()
 {
     $users = User::find(array('conditions' => 'idAccount = ?1', 'bind' => array(1 => $this->user->idAccount)));
     $tvisits = Visittype::find(array('conditions' => 'idAccount = ?1', 'bind' => array(1 => $this->user->idAccount)));
     $clients = Client::find(array('conditions' => 'idAccount = ?1', 'bind' => array(1 => $this->user->idAccount)));
     $this->view->setVar('users', $users);
     $this->view->setVar('tvisits', $tvisits);
     $this->view->setVar('clients', $clients);
 }
Example #6
0
 public function action_do_delete($client_id)
 {
     $client = Client::find($client_id);
     if (empty($client)) {
         return Redirect::back();
     }
     $client->modpacks()->delete();
     $client->delete();
     Cache::forget('clients');
     return Redirect::to('client/list')->with('success', 'Client deleted!');
 }
 public function postDelete($client_id)
 {
     $client = Client::find($client_id);
     if (empty($client)) {
         return Redirect::to('client/list')->withErrors(new MessageBag(array('Client UUID not found')));
     }
     $client->modpacks()->sync(array());
     $client->delete();
     Cache::forget('clients');
     return Redirect::to('client/list')->with('success', 'Client deleted!');
 }
Example #8
0
 function logout()
 {
     if ($this->user) {
         $update = User::find($this->user->id);
     } else {
         $update = Client::find($this->client->id);
     }
     $update->last_active = 0;
     $update->save();
     User::logout();
     redirect('login');
 }
Example #9
0
 public function postUpdateclient()
 {
     $id = Input::get('id');
     $client = Client::find($id);
     $client->name = Input::get('name');
     $client->email = Input::get('email');
     $client->mobile = Input::get('mobile');
     $client->city = Input::get('city');
     $client->address1 = Input::get('address1');
     $client->address2 = Input::get('address2');
     $client->save();
     return Response::json($client);
 }
 public function clientsAction($index = null)
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     if (!isset($index) || !is_numeric($index)) {
         $clients = Client::find();
         $this->view->setVars(array("model" => "Clients", "objects" => $clients));
         $this->jquery->getOnClick(".edit", "Accueil/clients/", "#ajax-content");
     } else {
         $client = Client::findFirst($index);
         $this->view->setVars(array("model" => "Clients", "client" => $client));
         $this->view->pick("Accueil/client");
     }
 }
Example #11
0
 function testFind()
 {
     //Arrange
     $id = null;
     $client_name = "Nico";
     $stylist_id = 1;
     $test_client = new Client($id, $client_name, $stylist_id);
     $test_client->save();
     $client_name2 = "Al";
     $stylist_id2 = 2;
     $test_client2 = new Client($id, $client_name2, $stylist_id2);
     $test_client2->save();
     //Act
     $result = Client::find($test_client->getId());
     //Assert
     $this->assertEquals($test_client, $result);
 }
Example #12
0
 protected function _checkUser()
 {
     if (fnGet($this->input, 'access_token') == '') {
         $this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '参数[access_token]不能为空'), 400);
     }
     // 设置当前用户和客户端
     $this->session->setUser($user = new User())->setClient($client = new Client());
     $passportConfig = $this->config->get("api.passport");
     // 尝试从缓存获取 userInfo
     if ($this->_userInfo = S($cacheKey = 'access_token_info.' . fnGet($this->input, 'access_token'))) {
         $user->find(fnGet($this->_userInfo, 'user_id'));
         $client->find(fnGet($this->_userInfo, 'client_id'));
         return;
     }
     // 向 passport 请求 userInfo
     $time = time();
     $url = str_replace('internal-resource/user-info?', '', $passportConfig->passportUrl) . 'internal-resource/user-info';
     $params = array('access_token' => fnGet($this->input, 'access_token'), 'app' => $passportConfig->passportApp, 'time' => $time);
     $sign = md5(implode('', $params) . $passportConfig->passportSecret);
     $params['sign'] = $sign;
     $http = new HttpClient();
     $response = $http->request($url, $params);
     $data = json_decode($response, true);
     if (fnGet($data, 'id')) {
         //检测用户是否已经保存
         $user->getByUsername($username = fnGet($data, 'username'));
         if (!($userId = $user->getId()) || !$user->getData('passport_id') || $user->getData('mobile') != fnGet($data, 'mobile')) {
             $user->addData(array('username' => $username, 'email' => fnGet($data, 'email'), 'mobile' => fnGet($data, 'mobile'), 'passport_id' => fnGet($data, 'passport_id'), 'avatar' => fnGet($data, 'avatar'), 'nickname' => fnGet($data, 'nickname')));
             $user->save();
             $userId = $user->getId();
         }
         //检测客户端是否已经保存
         $client->getByAppId($appId = fnGet($data, 'client_info/id'));
         if (!($clientId = $client->getId()) || $client->getScopes() != fnGet($data, 'client_info/scopes')) {
             $client->addData(array('client' => $appId, 'name' => fnGet($data, 'client_info/name'), 'app_secret' => fnGet($data, 'client_info/secret'), 'developerurl' => fnGet($data, 'client_info/endpoint'), 'scopes' => fnGet($data, 'client_info/scopes')));
             $client->save();
             $clientId = $client->getId();
         }
         $this->_userInfo = array('user_id' => $userId, 'client_id' => $clientId, 'username' => $username, 'session_data' => fnGet($data, 'session_data'));
         S($cacheKey, $this->_userInfo, 3600);
         return;
     }
     $this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '用户无效'), 400);
 }
Example #13
0
 public static function validate_login($username, $password)
 {
     $user = User::find_by_username($username);
     $client = Client::find_by_email_and_inactive($username, 0);
     if ($user && $user->validate_password($password) && $user->status == 'active') {
         User::login($user->id, 'user_id');
         $update = User::find($user->id);
         $update->last_login = time();
         $update->save();
         return $user;
     } elseif ($client && $client->password == $password && $client->inactive == '0') {
         User::login($client->id, 'client_id');
         $update = Client::find($client->id);
         $update->last_login = time();
         $update->save();
         return $client;
     } else {
         return FALSE;
     }
 }
 function test_client_find()
 {
     //Arrange
     $name = "Vidal Sassoon";
     $test_stylist = new Stylist($name);
     $test_stylist->save();
     $name2 = "Sweeney Todd";
     $test_stylist2 = new Stylist($name2);
     $test_stylist2->save();
     $name3 = "Mr. T";
     $stylist_id = $test_stylist->getId();
     $test_client = new Client($name3, $stylist_id, null);
     $test_client->save();
     $name4 = "Mrs. T";
     $stylist_id2 = $test_stylist2->getId();
     $test_client2 = new Client($name4, $stylist_id2, null);
     $test_client2->save();
     //Act
     $result = Client::find($test_client->getId());
     //Assert
     $this->assertEquals($test_client, $result);
 }
Example #15
0
 /**
  * Test shorthand methods
  *
  * @return void
  */
 public function testShorthandForm()
 {
     $fields = array('name', 'email', 'password:password', 'password2:password' => 'Confirm Password', 'user_source:select' => array('label' => 'How did you hear about us?', 'options' => array('friend' => 'From a friend', 'google' => 'Google search', 'other' => 'Other')));
     $instance = Client::find(542);
     $form = Squi\Form::make($fields, $instance);
     $expected = $this->markup('shorthand_table');
     $this->assertSame($expected, $form->render());
     $form = Squi\Form::basic($fields, $instance);
     $expected = $this->markup('shorthand_basic');
     $this->assertSame($expected, $form->render());
     $form = Squi\Form::table($fields, $instance);
     $expected = $this->markup('shorthand_table');
     $this->assertSame($expected, $form->render());
     $form = Squi\Form::bootstrap($fields, $instance);
     $expected = $this->markup('shorthand_bootstrap');
     $this->assertSame($expected, $form->render());
     $form = Squi\Form::of('Client', $instance, 'custom_field_method');
     $expected = $this->markup('shorthand_custom');
     $this->assertSame($expected, $form->render());
     $form = Squi\Form::of($instance);
     $expected = $this->markup('shorthand_model');
     $this->assertSame($expected, $form->render());
 }
Example #16
0
 public function updateAdmin()
 {
     $client = Client::find(Auth::user()->idClient);
     if (Input::get('emailClient') !== $client->emailClient) {
         $rules = array('emailClient' => 'required|email|unique:client,emailClient', 'emailClient2' => 'required|email|same:emailClient');
         $messages = array('required' => ':attribute est requis pour la modification', 'same' => 'Les adresses email entrées ne correspondent pas', 'unique' => 'Cette adresse email est déjà utilisée', 'email' => 'Ce n\'est pas une adresse email valide');
         $validator = Validator::make(Input::all(), $rules, $messages);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to(URL::previous())->withErrors($validator);
         } else {
             $input = ["emailClient" => Input::get('emailClient')];
             $client->fill($input)->save();
             Session::flash('flash_msg', "Votre compte a bien été mis à jour.");
             Session::flash('flash_type', "success");
         }
     }
     $input = ["adresseClient" => Input::get('adresseClient'), "adresseClient2" => Input::get('adresseClient2')];
     $client->fill($input)->save();
     Session::flash('flash_msg', "Votre compte a bien été mis à jour.");
     Session::flash('flash_type', "success");
     return Redirect::to(URL::previous());
 }
Example #17
0
 function testFind()
 {
     //Arrange
     $id = null;
     $name = "Martha Stewart";
     $phone = "(888) 888-8888";
     $next_visit = "2015-09-06";
     $stylist_id = 1;
     $test_client = new Client($id, $name, $phone, $next_visit, $stylist_id);
     $test_client->save();
     $name2 = "Jennifer Lopez";
     $phone2 = "(609) 999-9999";
     $next_visit2 = "2015-10-12";
     $stylist_id2 = 2;
     $test_client2 = new Client($id, $name2, $phone2, $next_visit2, $stylist_id2);
     $test_client2->save();
     //Act
     $result = Client::find($test_client->getId());
     //Assert
     $this->assertEquals($test_client, $result);
 }
Example #18
0
 public function getIndex()
 {
     $id = Input::get('id');
     return Client::find($id);
 }
Example #19
0
 public function storeNota()
 {
     $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first();
     $branch = Branch::where("id", Session::get('branch_id'))->first();
     $invoice = Invoice::createNew();
     $invoice->setBranch(Session::get('branch_id'));
     $invoice->setTerms(trim(Input::get('terms')));
     $invoice->setPublicNotes(trim(Input::get('public_notes')));
     $invoice->setInvoiceDate(trim(Input::get('invoice_date')));
     $invoice->setClient(trim(Input::get('client')));
     $invoice->setEconomicActivity($branch->economic_activity);
     $dateparser = explode("/", Input::get('due_date'));
     if (Input::get('due_date')) {
         $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
         $invoice->setDueDate($date);
     }
     $invoice->setDiscount(trim(Input::get('discount')));
     $invoice->setClientName(trim(Input::get('razon')));
     $invoice->setClientNit(trim(Input::get('nit')));
     $invoice->setUser(Auth::user()->id);
     $dateparser = explode("/", Input::get('invoice_date'));
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $invoice->setInvoiceDate($date);
     $invoice->importe_neto = trim(Input::get('total'));
     $invoice->importe_total = trim(Input::get('subtotal'));
     //$invoice->note = trim(Input::get('nota'));
     if (Input::get('nota')) {
         $nota = array();
         $nota[0] = ['date' => date('d-m-Y H:i:s'), 'note' => '<b>' . Auth::user()->first_name . " " . Auth::user()->last_name . "</b>: " . trim(Input::get('nota'))];
         $invoice->note = json_encode($nota);
     }
     //ACCOUTN AND BRANCK
     $invoice->balance = trim(Input::get('total'));
     $invoice->setAccountName($account->name);
     //$invoice->setAccountNit($account->nit);
     $invoice->setBranchName($branch->name);
     $invoice->setAddress1($branch->address1);
     $invoice->setAddress2($branch->address2);
     $invoice->setPhone($branch->work_phone);
     //$invoice->setCity($branch->city);
     //$invoice->setState($branch->state);
     //$invoice->setNumberAutho($branch->number_autho);
     //$invoice->setKeyDosage($branch->key_dosage);
     //$invoice->setTypeThird($branch->type_third);
     //$invoice->setDeadline($branch->deadline);
     //$invoice->setLaw($branch->law);
     $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->first();
     //$invoice->invoice_number = branch::getInvoiceNumber();
     $number = 1;
     $the_last = Invoice::where('account_id', Auth::user()->account_id)->where('branch_id', Session::get('branch_id'))->whereNotNull('document_number')->orderBy('document_number', 'DESC')->first();
     if (isset($the_last->document_number)) {
         $number = $the_last->document_number + 1;
     }
     $invoice->document_number = $number;
     //echo Session::get('branch_id')." ".$number." ".$the_last->document_number." -";
     //            if(Input::get('printer_type')==1)
     //                $invoice->setJavascript($type_document->javascript_web);
     //            else
     //                $invoice->setJavascript($type_document->javascript_pos);
     //            $document = TypeDocumentBranch::where('branch_id',$invoice->branch_id)->orderBy('type_document_id','DESC')->first();
     //            $type_document =TypeDocument::where('id',$document->type_document_id)->first();
     //            $invoice->setJavascript($type_document->javascript_web);
     //            $invoice->logo = $type_document->logo;
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 2) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     //$type_document =TypeDocument::where('id',$document->type_document_id)->first();
     //$invoice->setJavascript($type_document->javascript_web);
     if (Input::get('printer_type') == 1) {
         $invoice->logo = 1;
     } else {
         $invoice->logo = 0;
     }
     $invoice->save();
     foreach (Input::get('productos') as $producto) {
         $prod = $producto;
         $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $producto["'product_key'"])->first();
         if ($product != null) {
             $invoiceItem = InvoiceItem::createNew();
             $invoiceItem->setInvoice($invoice->id);
             $invoiceItem->setProduct($product->id);
             $invoiceItem->setProductKey($producto["'product_key'"]);
             $proo = DB::table('products')->where('product_key', '=', $producto["'product_key'"])->first();
             $invoiceItem->setNotes($proo->notes);
             $invoiceItem->setCost($producto["'cost'"]);
             $invoiceItem->setQty($producto["'qty'"]);
             $invoiceItem->save();
         }
     }
     //adicionando cargo al cliente
     $cliente = Client::find($invoice->client_id);
     $cliente->balance = $cliente->balance + $invoice->balance;
     $cliente->save();
     $newInvoice = Invoice::where('id', '=', $invoice->getId())->first();
     return Redirect::to("factura/" . $newInvoice->getPublicId());
 }
Example #20
0
    function view($id = FALSE, $filter = FALSE, $additional = FALSE)
    {
        $this->view_data['submenu'] = array($this->lang->line('application_back') => 'messages');
        $message = Privatemessage::find_by_id($id);
        $this->view_data["count"] = "1";
        if (!$filter || $filter == "Marked") {
            if ($message->status == "New") {
                $message->status = 'Read';
                $message->save();
            }
            $this->view_data["filter"] = FALSE;
            $sql = 'SELECT privatemessages.id, privatemessages.conversation FROM privatemessages
        				WHERE privatemessages.recipient = "u' . $this->user->id . '" AND privatemessages.`id`="' . $id . '"';
            $query = $this->db->query($sql);
            $row = $query->row();
            $sql2 = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.conversation, privatemessages.attachment, privatemessages.attachment_link, privatemessages.subject, privatemessages.message, privatemessages.sender, privatemessages.recipient, privatemessages.`time`, privatemessages.`sender` , clients.`userpic` as userpic_c, users.`userpic` as userpic_u , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c, CONCAT(rec_u.firstname," ", rec_u.lastname) as recipient_u, CONCAT(rec_c.firstname," ", rec_c.lastname) as recipient_c
        				FROM privatemessages
        				LEFT JOIN clients ON CONCAT("c",clients.id) = privatemessages.sender
        				LEFT JOIN users ON CONCAT("u",users.id) = privatemessages.sender
        				LEFT JOIN clients AS rec_c ON CONCAT("c",rec_c.id) = privatemessages.recipient
        				LEFT JOIN users AS rec_u ON CONCAT("u",rec_u.id) = privatemessages.recipient

        				GROUP by privatemessages.id HAVING privatemessages.conversation = "' . $row->conversation . '" ORDER BY privatemessages.`id` DESC LIMIT 100';
            $query2 = $this->db->query($sql2);
            $this->view_data["conversation"] = array_filter($query2->result());
            $this->view_data["count"] = count($this->view_data["conversation"]);
        } else {
            if ($message->status == 'deleted') {
                $sql = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.conversation, privatemessages.attachment, privatemessages.attachment_link, privatemessages.subject, privatemessages.message, privatemessages.sender, privatemessages.recipient, privatemessages.`time`, privatemessages.`sender` , clients.`userpic` as userpic_c, users.`userpic` as userpic_u , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c, CONCAT(users.firstname," ", users.lastname) as recipient_u, CONCAT(clients.firstname," ", clients.lastname) as recipient_c
        				FROM privatemessages
        				LEFT JOIN clients ON (CONCAT("c",clients.id) = privatemessages.sender) OR (CONCAT("c",clients.id) = privatemessages.recipient)
        				LEFT JOIN users ON (CONCAT("u",users.id) = privatemessages.sender) OR (CONCAT("u",users.id) = privatemessages.recipient)
        				GROUP by privatemessages.id HAVING privatemessages.id = "' . $id . '" AND privatemessages.recipient = "u' . $this->user->id . '" ORDER BY privatemessages.`id` DESC LIMIT 100';
            } else {
                if ($filter == "Sent") {
                    $sql = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.conversation, privatemessages.attachment, privatemessages.attachment_link, privatemessages.subject, privatemessages.message, privatemessages.sender, privatemessages.recipient, privatemessages.`time`, privatemessages.`sender` , clients.`userpic` as userpic_c, users.`userpic` as userpic_u , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c, CONCAT(users.firstname," ", users.lastname) as recipient_u, CONCAT(clients.firstname," ", clients.lastname) as recipient_c
        				FROM privatemessages
        				LEFT JOIN clients ON CONCAT("c",clients.id) = privatemessages.recipient OR CONCAT("c",clients.id) = privatemessages.sender
        				LEFT JOIN users ON  CONCAT("u",users.id) = privatemessages.recipient OR CONCAT("u",users.id) = privatemessages.sender
        				GROUP by privatemessages.id HAVING privatemessages.id = "' . $id . '" AND privatemessages.sender = "u' . $this->user->id . '" ORDER BY privatemessages.`id` DESC LIMIT 100';
                    $receiverart = substr($additional, 0, 1);
                    $receiverid = substr($additional, 1, 9999);
                    if ($receiverart == "u") {
                        $receiver = User::find($receiverid);
                        $this->view_data["recipient"] = $receiver->firstname . ' ' . $receiver->lastname;
                    } else {
                        $receiver = Client::find($receiverid);
                        $this->view_data["recipient"] = $receiver->firstname . ' ' . $receiver->lastname;
                    }
                } else {
                    $sql = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.conversation, privatemessages.attachment, privatemessages.attachment_link, privatemessages.subject, privatemessages.message, privatemessages.sender, privatemessages.recipient, privatemessages.`time`, privatemessages.`sender` , clients.`userpic` as userpic_c, users.`userpic` as userpic_u , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c, CONCAT(users.firstname," ", users.lastname) as recipient_u, CONCAT(clients.firstname," ", clients.lastname) as recipient_c
        				FROM privatemessages
        				LEFT JOIN clients ON (CONCAT("c",clients.id) = privatemessages.sender) OR (CONCAT("c",clients.id) = privatemessages.recipient)
        				LEFT JOIN users ON (CONCAT("u",users.id) = privatemessages.sender) OR (CONCAT("u",users.id) = privatemessages.recipient)
        				GROUP by privatemessages.id HAVING privatemessages.id = "' . $id . '" AND (privatemessages.sender = "u' . $this->user->id . '" OR privatemessages.recipient = "u' . $this->user->id . '") ORDER BY privatemessages.`id` DESC LIMIT 100';
                }
            }
            $query = $this->db->query($sql);
            $this->view_data["conversation"] = array_filter($query->result());
            $this->view_data["filter"] = $filter;
        }
        $this->theme_view = 'ajax';
        $this->view_data['form_action'] = 'messages/write';
        $this->view_data['id'] = $id;
        $this->content_view = 'messages/view';
    }
Example #21
0
    $stylist->delete();
    return $app['twig']->render('index.html.twig', array('stylists' => Stylist::getAll()));
});
//allows the user to find a client's id
$app->get("/clients/{id}", function ($id) use($app) {
    $client = Client::find($id);
    return $app['twig']->render('client.html.twig', array('client' => $client));
});
$app->get("/clients/{id}/edit", function ($id) use($app) {
    $client = Client::find($id);
    return $app['twig']->render('client.html.twig', array('client' => $client));
});
//Allows the user to update the client
$app->patch("/clients/{id}", function ($id) use($app) {
    $client_name = $_POST['client_name'];
    $client = Client::find($id);
    $stylist = Stylist::find($id);
    $client->update($client_name);
    return $app['twig']->render('client.html.twig', array('client' => $client));
});
//Allows a user to delete a client
//Getting error: Impossible to access attribute getStylistName
//on null variable in stylist.html.twig at 8.
$app->delete("/clients/{id}", function ($id) use($app) {
    $client = Client::find($id);
    $stylist = Stylist::find($client->getStylistId());
    $client->delete();
    $clients = Client::getAll();
    return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $clients));
});
return $app;
 /**
  * Show the form for editing the specified client.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $client = Client::find($id);
     return View::make('clients.edit', compact('client'));
 }
Example #23
0
    // return $app['twig']->render('category.html.twig',
    // array('category' => $category, 'tasks' => $category->getTasks()));
});
$app->patch("/stylists/{id}/edit", function ($id) use($app) {
    $name = preg_quote($_POST['name'], "'");
    $stylist = Stylist::find($id);
    $stylist->update($name);
    return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients()));
});
$app->patch("/clients/{id}/edit", function ($id) use($app) {
    $name = preg_quote($_POST['client_name'], "'");
    $client = Client::find($id);
    // echo "Name: " . $name . "   Id: " . $id . "   ";
    // var_dump($client);
    $client->update($name);
    return $app['twig']->render('client_edit.html.twig', array('client' => Client::find($id)));
});
$app->delete("/stylists/{id}", function ($id) use($app) {
    $stylist = Stylist::find($id);
    $stylist->delete();
    return $app['twig']->render('index.html.twig', array('stylists' => Stylist::getAll()));
});
$app->get("/stylists/{id}/edit", function ($id) use($app) {
    $stylist = Stylist::find($id);
    return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist));
});
$app->post("/delete_stylists", function () use($app) {
    Stylist::deleteAll();
    return $app['twig']->render('delete_stylists.html.twig');
});
$app->post("/delete_clients", function () use($app) {
 public function destroy($id)
 {
     Client::find($id)->delete();
 }
Example #25
0
 function credentials($id = FALSE, $email = FALSE, $newPass = FALSE)
 {
     if ($email) {
         $this->load->helper('file');
         $client = Client::find($id);
         $client->password = $client->set_password($newPass);
         $client->save();
         $setting = Setting::first();
         $this->email->from($setting->email, $setting->company);
         $this->email->to($client->email);
         $this->email->subject($setting->credentials_mail_subject);
         $this->load->library('parser');
         $parse_data = array('client_contact' => $client->firstname . ' ' . $client->lastname, 'client_company' => $client->company->name, 'client_link' => $setting->domain, 'company' => $setting->company, 'username' => $client->email, 'password' => $newPass, 'logo' => '<img src="' . base_url() . '' . $setting->logo . '" alt="' . $setting->company . '"/>', 'invoice_logo' => '<img src="' . base_url() . '' . $setting->invoice_logo . '" alt="' . $setting->company . '"/>');
         $message = read_file('./application/views/' . $setting->template . '/templates/email_credentials.html');
         $message = $this->parser->parse_string($message, $parse_data);
         $this->email->message($message);
         if ($this->email->send()) {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_send_login_details_success'));
         } else {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_send_login_details_error'));
         }
         redirect('clients/view/' . $client->company_id);
     } else {
         $this->view_data['client'] = Client::find($id);
         $this->theme_view = 'modal';
         function random_password($length = 8)
         {
             $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
             $password = substr(str_shuffle($chars), 0, $length);
             return $password;
         }
         $this->view_data['new_password'] = random_password();
         $this->view_data['title'] = $this->lang->line('application_login_details');
         $this->view_data['form_action'] = 'clients/credentials';
         $this->content_view = 'clients/_credentials';
     }
 }
Example #26
0
 function client($id = FALSE)
 {
     $this->load->helper('notification');
     if ($_POST) {
         unset($_POST['send']);
         unset($_POST['_wysihtml5_mode']);
         $id = $_POST['id'];
         unset($_POST['id']);
         $client = Client::find_by_id($_POST['client_id']);
         $assign = Ticket::find_by_id($id);
         $attr = array('client_id' => $client->id, 'company_id' => $client->company->id);
         $assign->update_attributes($attr);
         if (isset($_POST['notify'])) {
             send_ticket_notification($client->email, '[Ticket#' . $assign->reference . '] - ' . $_POST['subject'], $_POST['message'], $assign->id);
             $_POST['internal'] = "0";
         }
         unset($_POST['notify']);
         $_POST['subject'] = htmlspecialchars($_POST['subject']);
         $_POST['datetime'] = time();
         $_POST['from'] = $this->user->firstname . " " . $this->user->lastname . ' - ' . $this->user->email;
         $_POST['reply_to'] = $this->user->email;
         $_POST['ticket_id'] = $id;
         $_POST['to'] = $_POST['client_id'];
         unset($_POST['client_id']);
         $article = TicketHasArticle::create($_POST);
         if (!$assign) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_ticket_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_assign_ticket_success'));
         }
         redirect('tickets/view/' . $id);
     } else {
         $this->view_data['clients'] = Client::find('all', array('conditions' => array('inactive=?', '0')));
         $this->view_data['ticket'] = Ticket::find($id);
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_client');
         $this->view_data['form_action'] = 'tickets/client';
         $this->content_view = 'tickets/_client';
     }
 }
Example #27
0
 function write($ajax = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         unset($_POST['_wysihtml5_mode']);
         $message = $_POST['message'];
         $receiverart = substr($_POST['recipient'], 0, 1);
         $receiverid = substr($_POST['recipient'], 1, 9999);
         if ($receiverart == "u") {
             $receiver = User::find($receiverid);
             $receiveremail = $receiver->email;
         } else {
             $receiver = Client::find($receiverid);
             $receiveremail = $receiver->email;
         }
         $_POST = array_map('htmlspecialchars', $_POST);
         $_POST['message'] = $message;
         $_POST['time'] = date('Y-m-d H:i', time());
         $_POST['sender'] = "u" . $this->user->id;
         $_POST['status'] = "New";
         if (!isset($_POST['conversation'])) {
             $_POST['conversation'] = random_string('sha1');
         }
         $message = Privatemessage::create($_POST);
         if (!$message) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_write_message_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_write_message_success'));
             $this->load->helper('notification');
             send_notification($receiveremail, $this->lang->line('application_notification_new_message_subject'), $this->lang->line('application_notification_new_message') . '<br><hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>' . $_POST['message'] . '<hr style="border-top: 1px solid #CCCCCC; border-left: 1px solid whitesmoke; border-bottom: 1px solid whitesmoke;"/>');
         }
         if ($ajax != "reply") {
             redirect('messages');
         } else {
             $this->theme_view = 'ajax';
         }
     } else {
         $this->view_data['clients'] = Client::find('all', array('conditions' => array('inactive=?', '0')));
         $this->view_data['users'] = User::find('all', array('conditions' => array('status=?', 'active')));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_write_message');
         $this->view_data['form_action'] = 'messages/write';
         $this->content_view = 'messages/_messages';
     }
 }
Example #28
0
 public function testClientDeleteGet()
 {
     $client = Client::find(1);
     $this->call('GET', '/client/delete/' . $client->id);
     $this->assertResponseOk();
 }
 public function testMorph()
 {
     $user = User::create(array('name' => 'John Doe'));
     $client = Client::create(array('name' => 'Jane Doe'));
     $photo = Photo::create(array('url' => 'http://graph.facebook.com/john.doe/picture'));
     $photo = $user->photos()->save($photo);
     $this->assertEquals(1, $user->photos->count());
     $this->assertEquals($photo->id, $user->photos->first()->id);
     $user = User::find($user->_id);
     $this->assertEquals(1, $user->photos->count());
     $this->assertEquals($photo->id, $user->photos->first()->id);
     $photo = Photo::create(array('url' => 'http://graph.facebook.com/jane.doe/picture'));
     $client->photo()->save($photo);
     $this->assertNotNull($client->photo);
     $this->assertEquals($photo->id, $client->photo->id);
     $client = Client::find($client->_id);
     $this->assertNotNull($client->photo);
     $this->assertEquals($photo->id, $client->photo->id);
     $photo = Photo::first();
     $this->assertEquals($photo->imageable->name, $user->name);
     $user = User::with('photos')->find($user->_id);
     $relations = $user->getRelations();
     $this->assertTrue(array_key_exists('photos', $relations));
     $this->assertEquals(1, $relations['photos']->count());
     $photos = Photo::with('imageable')->get();
     $relations = $photos[0]->getRelations();
     $this->assertTrue(array_key_exists('imageable', $relations));
     $this->assertInstanceOf('User', $relations['imageable']);
     $relations = $photos[1]->getRelations();
     $this->assertTrue(array_key_exists('imageable', $relations));
     $this->assertInstanceOf('Client', $relations['imageable']);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $client = Client::find($id);
     $client->delete();
     return Redirect::to('admin/client')->with('success_message', 'El registro ha sido borrado correctamente.')->withInput();
 }