/** * Upload documents * @param $uploadType * @param bool $withoutMessage * @return int */ public static function uploadDocuments($uploadType, $withoutMessage = false) { if(isset($_SESSION[$uploadType]) && count($_SESSION[$uploadType]) > 0) { $settings = UsersSettings::model()->findByAttributes(array( 'User_ID' => Yii::app()->user->userID, )); //get default bank account $condition = new CDbCriteria(); $condition->condition = "users_project_list.User_ID = '" . Yii::app()->user->userID . "'"; $condition->addCondition("users_project_list.Client_ID = '" . Yii::app()->user->clientID . "'"); $condition->addCondition("t.Account_Num_ID = '" . $settings->Default_Bank_Acct . "'"); $condition->join = "LEFT JOIN projects ON projects.Project_ID = t.Project_ID LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID"; $bankAcct = BankAcctNums::model()->with('client.company', 'project')->find($condition); $defaultBankAcct = 0; if ($bankAcct) { $defaultBankAcct = $settings->Default_Bank_Acct; } //get user to send email $person_to_email = false; if (Yii::app()->user->id != 'user' && Yii::app()->user->id != 'single_user') { $person_to_email = Users::model()->with('person')->findByPk(Yii::app()->user->userID); } else { $condition = new CDbCriteria(); $condition->join = "LEFT JOIN users_client_list ON users_client_list.User_ID = t.User_ID"; $condition->addInCondition('users_client_list.User_Type', array(UsersClientList::APPROVER, UsersClientList::PROCESSOR, UsersClientList::CLIENT_ADMIN)); $condition->addInCondition('t.User_Type', array(Users::ADMIN, Users::DB_ADMIN, Users::DATA_ENTRY_CLERK), "OR"); $condition->addCondition("users_client_list.Client_ID = '" . Yii::app()->user->clientID . "'"); $person_to_email = Users::model()->with('person')->find($condition); } foreach ($_SESSION[$uploadType] as $key => $current_upload_file) { // check fed id if ($current_upload_file['doctype'] == self::W9) { if (!preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})|(IN[-]\d{6})|(T0[-]\d{7})$/', $current_upload_file['fed_id'])) { return 2; } } } // insert documents into DB foreach ($_SESSION[$uploadType] as $key => $current_upload_file) { if (file_exists($current_upload_file['filepath'])) { // create document $document = new Documents(); $document->Document_Type = $current_upload_file['doctype']; $document->User_ID = Yii::app()->user->userID; $document->Client_ID = Yii::app()->user->clientID; $document->Project_ID = Yii::app()->user->projectID; $document->Created = date("Y-m-d H:i:s"); $document->save(); $new_doc_id=$document->Document_ID; Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD); // insert image $image = new Images(); $imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath']))); //$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']); $image->Document_ID = $document->Document_ID; $image->Img = $imageData; $image->File_Name = $current_upload_file['name']; $image->Mime_Type = $current_upload_file['mimetype']; $image->File_Hash = sha1_file($current_upload_file['filepath']); $image->File_Size = intval(filesize($current_upload_file['filepath'])); $image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']); $image->save(); $infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY); if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '') || $current_upload_file['mimetype'] != 'application/pdf') { Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80); } // delete file from temporary catalog and from cache table //unlink($current_upload_file['filepath']); FileCache::deleteBothFromCacheById($current_upload_file['file_id']); if ($current_upload_file['doctype'] == self::W9) { // if document is W9 // get additional fields $fedId = trim($current_upload_file['fed_id']); $newCompanyName = trim($current_upload_file['company_name']); // get company info $company = Companies::model()->with('client')->findByAttributes(array( 'Company_Fed_ID' => $fedId, )); // create w9 $W9 = new W9(); $W9->Document_ID = $document->Document_ID; $W9->W9_Owner_ID = Yii::app()->user->clientID; $W9->Creator_ID = Yii::app()->user->userID; $W9->Business_Name = trim($current_upload_file['bus_name']); $W9->Tax_Class = trim($current_upload_file['tax_name']); // get user info $user = Users::model()->with('person')->findByPk(Yii::app()->user->userID); if ($company) { // if company exisits $client = $company->client; //fill created company with dataentry values from session Companies::fillWithSessionDataEntry($company,$current_upload_file); $existingW9 = W9::model()->findByAttributes(array( 'Client_ID' => $client->Client_ID, 'W9_Owner_ID' => Yii::app()->user->clientID, )); if ($existingW9) { $W9->Revision_ID = -1; } else { $W9->Revision_ID = 0; } $vendor = Vendors::model()->findByAttributes(array( 'Client_Client_ID' => Yii::app()->user->clientID, 'Vendor_Client_ID' => $client->Client_ID, )); if (isset($vendor->Active_Relationship) && $vendor->Active_Relationship == Vendors::NOT_ACTIVE_RELATIONSHIP) { $vendor->Active_Relationship = Vendors::ACTIVE_RELATIONSHIP; $vendor->save(); } else if (!$vendor && Yii::app()->user->clientID != 0 && Yii::app()->user->clientID != $client->Client_ID) { $vendor = new Vendors(); $vendor->Vendor_ID_Shortcut = ''; $vendor->Vendor_Client_ID = $client->Client_ID; $vendor->Client_Client_ID = Yii::app()->user->clientID; $vendor->Vendor_Name_Checkprint = ''; $vendor->Vendor_1099 = ''; $vendor->Vendor_Default_GL = ''; $vendor->Vendor_Default_GL_Note = ''; $vendor->Vendor_Note_General = ''; $vendor->Vendor_Contact = trim($current_upload_file['contact']); $vendor->Vendor_Phone = trim($current_upload_file['phone']); $vendor->save(); } } else { //if company does not exists, create new company $client = Companies::createEmptyCompany($fedId, $newCompanyName); $company_model = Companies::model()->findByPk($client->Company_ID); //fill created company with dataentry values from session Companies::fillWithSessionDataEntry($company_model,$current_upload_file); if (Yii::app()->user->clientID != 0) { $vendor = new Vendors(); $vendor->Vendor_ID_Shortcut = ''; $vendor->Vendor_Client_ID = $client->Client_ID; $vendor->Client_Client_ID = Yii::app()->user->clientID; $vendor->Vendor_Name_Checkprint = ''; $vendor->Vendor_1099 = ''; $vendor->Vendor_Default_GL = ''; $vendor->Vendor_Default_GL_Note = ''; $vendor->Vendor_Note_General = ''; $vendor->Vendor_Contact = trim($current_upload_file['contact']); $vendor->Vendor_Phone = trim($current_upload_file['phone']); $vendor->save(); } $W9->Revision_ID = 0; } // save w9 $W9->Client_ID = $client->Client_ID; $W9->save(); if ($person_to_email) { Mail::sendNewW9ForDataEntry($person_to_email->person->Email, $person_to_email->person->First_Name, $person_to_email->person->Last_Name); } } else if ($current_upload_file['doctype'] == self::AP) { //create aps $aps = new Aps(); $aps->Document_ID = $document->Document_ID; $aps->Vendor_ID = 0; $aps->PO_ID = 0; $aps->AP_Approval_Value = Aps::NOT_READY_FOR_APPROVAL; $aps->Invoice_Number = 0; $aps->save(); } else if ($current_upload_file['doctype'] == self::PM) { //create payment $payment = new Payments(); $payment->Document_ID = $document->Document_ID; $payment->Vendor_ID = 0; $payment->Payment_Check_Number = 0; $payment->Payment_Amount = 0; if ($defaultBankAcct != 0) { $payment->Account_Num_ID = $defaultBankAcct; } else { $payment->Account_Num_ID = 0; } $payment->save(); } else if ($current_upload_file['doctype'] == self::PO) { //create pos $po = new Pos(); $po->Document_ID = $document->Document_ID; $po->Vendor_ID = 0; $po->PO_Number = Pos::getNewPoNumber(); $po->PO_Date = date('Y-m-d'); $po->PO_Backup_Document_ID = 0; $po->save(); } else if ($current_upload_file['doctype'] == self::PR) { $payroll = new Payrolls(); $payroll->Document_ID = $document->Document_ID; $payroll->save(); } else if ($current_upload_file['doctype'] == self::JE) { $je = new Journals(); $je->Document_ID = $document->Document_ID; $je->save(); } else if ($current_upload_file['doctype'] == self::PC) { $pc = new Pcs(); $pc->Document_ID = $document->Document_ID; $pc->save(); } else if ($current_upload_file['doctype'] == self::AR) { $ar = new Ars(); $ar->Document_ID = $document->Document_ID; $ar->save(); } } $arr[$current_upload_file['name']]['string']= Images::getAjaxStringForLastUploadSection($new_doc_id); $arr[$current_upload_file['name']]['key']=$key; } $_SESSION[$uploadType] = array(); if (!$withoutMessage) { Yii::app()->user->setFlash('success', "Documents have been uploaded!"); } return json_encode($arr); } else { $answer['empty']=1; return json_encode($answer); } }
public function actionGetRequestInfo() { if (Yii::app()->request->isAjaxRequest && isset($_POST['request_id']) ) { //get support_request info $sup_req = SupportRequests::model()->findByPk(intval($_POST['request_id'])); //get user questions $user = Users::model()->findByAttributes(array( 'User_Login'=>strval($_POST['login']), )); $user_id = $user->User_ID; $users_questions = UsersQuestions::getUserQuestions($user_id); $users_settings = UsersSettings::model()->findByAttributes(array( 'User_ID'=>$user_id )); $device= UsersDevices::model()->findByAttributes(array( 'Device_ID'=>$sup_req->User_Device_ID, 'Remote_Login'=>1 )); //return json to js $this->renderPartial('admin_side_view',array( 'sup_req'=>$sup_req, 'users_questions'=>$users_questions, 'device'=>$device, 'users_settings'=>$users_settings, 'user_id'=>$user_id )); } }
/** * Lists all models. */ public function actionIndex() { if (isset($_POST['oper']) && $_POST['oper'] == 'edit') { $userId = intval($_POST["id"]); $user = Users::model()->with('person')->findByPk($userId); if ($user) { $person = $user->person; $addresses = $person->adresses; if (isset($addresses[0])) { $address = $addresses[0]; $address->Address1 = $_POST["Address1"]; $address->Address2 = $_POST["Address2"]; $address->City = $_POST["City"]; $address->State = $_POST["State"]; $address->ZIP = $_POST["ZIP"]; $address->Country = $_POST["Country"]; $address->Phone = $_POST["Phone"]; $address->Fax = $_POST["Fax"]; if ($address->validate()) { $address->save(); echo "adresses\n"; } } $user->User_Login = $_POST["User_Login"]; $user->User_Type = $_POST["User_Type"]; $user->Last_Login = $_POST["Last_Login"] ? $_POST["Last_Login"] : null; $user->Active = intval($_POST["Active"]); if ($user->validate()) { $user->save(); echo "user\n"; } $person->First_Name = $_POST["First_Name"]; $person->Last_Name = $_POST["Last_Name"]; $person->Email = $_POST["Email"]; $person->Mobile_Phone = $_POST["Mobile_Phone"]; $person->Direct_Phone = $_POST["Direct_Phone"]; $person->Direct_Fax = $_POST["Direct_Fax"]; if ($person->validate()) { $person->save(); echo "person\n"; } } die; } if (isset($_POST['oper']) && $_POST['oper'] == 'add') { die; } if (isset($_POST['oper']) && $_POST['oper'] == 'del') { $userId = intval($_POST["id"]); $user = Users::model()->with('person')->findByPk($userId); $documents = Documents::model()->findByAttributes(array( 'User_ID' => $userId, )); if ($user && !$documents) { $person = $user->person; $addresses = $person->adresses; if (count($addresses) > 0) { foreach ($addresses as $address) { $address->delete(); } } PersonAddresses::model()->deleteAllByAttributes(array( 'Person_ID' => $person->Person_ID, )); $person->delete(); UsersSettings::model()->deleteAllByAttributes(array( 'User_ID' => $user->User_ID, )); UsersToApprove::model()->deleteAllByAttributes(array( 'User_ID' => $user->User_ID, )); UsersClientList::model()->deleteAllByAttributes(array( 'User_ID' => $user->User_ID, )); UsersProjectList::model()->deleteAllByAttributes(array( 'User_ID' => $user->User_ID, )); Notes::model()->deleteAllByAttributes(array( 'User_ID' => $user->User_ID, )); $user->delete(); } die; } $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword); mysql_select_db(Yii::app()->params->dbname); mysql_query("SET NAMES 'utf8'"); Yii::import('ext.phpgrid.inc.jqgrid'); // set columns $col = array(); $col["title"] = "User ID"; // caption of column $col["name"] = "User_ID"; $col["dbname"] = "users.User_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "Default Project"; // caption of column $col["name"] = "Default_Project"; $col["dbname"] = "users.Default_Project"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = true; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "User Login"; // caption of column $col["name"] = "User_Login"; $col["dbname"] = "users.User_Login"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "User Type"; // caption of column $col["name"] = "User_Type"; $col["dbname"] = "users.User_Type"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["edittype"] = "select"; $col["editoptions"] = array("value"=>'User:User;Admin:Admin;DB Admin:DB Admin;Data Entry Clerk:Data Entry Clerk'); $cols[] = $col; $col = array(); $col["title"] = "Last Login"; // caption of column $col["name"] = "Last_Login"; $col["dbname"] = "users.Last_Login"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Active"; // caption of column $col["name"] = "Active"; $col["dbname"] = "users.Active"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $col["edittype"] = "select"; $col["editoptions"] = array("value"=>'0:0;1:1'); $cols[] = $col; $col = array(); $col["title"] = "Last_IP"; // caption of column $col["name"] = "Last_IP"; $col["dbname"] = "users.Last_IP"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = false; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Person ID"; // caption of column $col["name"] = "Person_ID"; $col["dbname"] = "persons.Person_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "First Name"; // caption of column $col["name"] = "First_Name"; $col["dbname"] = "persons.First_Name"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Last Name"; // caption of column $col["name"] = "Last_Name"; $col["dbname"] = "persons.Last_Name"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Email"; // caption of column $col["name"] = "Email"; $col["dbname"] = "persons.Email"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Mobile Phone"; // caption of column $col["name"] = "Mobile_Phone"; $col["dbname"] = "persons.Mobile_Phone"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Direct Phone"; // caption of column $col["name"] = "Direct_Phone"; $col["dbname"] = "persons.Direct_Phone"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $col = array(); $col["title"] = "Direct Fax"; // caption of column $col["name"] = "Direct_Fax"; $col["dbname"] = "persons.Direct_Fax"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Address ID"; // caption of column $col["name"] = "Address_ID"; $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = true; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "Address1"; // caption of column $col["name"] = "Address1"; $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Address2"; // caption of column $col["name"] = "Address2"; $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "City"; // caption of column $col["name"] = "City"; $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "State"; // caption of column $col["name"] = "State"; $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "ZIP"; // caption of column $col["name"] = "ZIP"; $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Country"; // caption of column $col["name"] = "Country"; $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Phone"; // caption of column $col["name"] = "Phone"; $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Fax"; // caption of column $col["name"] = "Fax"; $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $g = new jqgrid(); $grid["caption"] = "Users"; // $grid["multiselect"] = true; $grid["autowidth"] = true; $grid["resizable"] = true; //$grid["toppager"] = true; $grid["sortname"] = 'persons.Last_Name'; $grid["sortorder"] = "ASC"; $grid["add_options"] = array( 'width'=>'420', "closeAfterEdit"=>true, // close dialog after add/edit "top"=>"200", // absolute top position of dialog "left"=>"200" // absolute left position of dialog ); $g->set_options($grid); $g->set_actions( array( "add"=>false, // allow/disallow add "edit"=>true, // allow/disallow edit "delete"=>true, // allow/disallow delete "rowactions"=>true, // show/hide row wise edit/del/save option "export"=>true, // show/hide export to excel option "autofilter" => true, // show/hide autofilter for search "search" => "advance" // show single/multi field search condition (e.g. simple or advance) ) ); $g->select_command = "SELECT addresses.*, persons.*, users.User_ID, users.Default_Project, users.User_Login, users.User_Type, users.Last_Login, users.Active, users.Last_IP FROM users LEFT JOIN persons ON users.Person_ID = persons.Person_ID LEFT JOIN person_addresses ON person_addresses.Person_ID = persons.Person_ID LEFT JOIN addresses ON addresses.Address_ID = person_addresses.Address_ID"; // set database table for CRUD operations $g->table = "users"; $g->set_columns($cols); // group columns header $g->set_group_header( array( "useColSpanStyle"=>true, "groupHeaders"=>array( array( "startColumnName"=>'User_ID', // group starts from this column "numberOfColumns"=>7, // group span to next 2 columns "titleText"=>'User Information' // caption of group header ), array( "startColumnName"=>'Person_ID', // group starts from this column "numberOfColumns"=>7, // group span to next 2 columns "titleText"=>'Person Information' // caption of group header ), array( "startColumnName"=>'Address1', // group starts from this column "numberOfColumns"=>8, // group span to next 2 columns "titleText"=>"User's Address" // caption of group header ) ) ) ); // render grid and get html/js output $out = $g->render("Users"); $this->render('index',array( 'out'=>$out, )); }