public function run() { $tpl = new template(); $id = (int) $_GET['id']; if ($id > 0) { $lead = $this->getLead($id); $values = array('name' => $lead['name'], 'potentialMoney' => $lead['potentialMoney'], 'actualMoney' => $lead['actualMoney'], 'refSource' => $lead['refSource'], 'refValue' => $lead['refValue'], 'status' => $lead['status'], 'proposal' => $lead['proposal']); $clients = new clients(); $dbClient = $clients->getClient($lead['clientId']); $client = array('name' => $dbClient['name'], 'street' => $dbClient['street'], 'zip' => $dbClient['zip'], 'city' => $dbClient['city'], 'state' => $dbClient['state'], 'country' => $dbClient['country'], 'phone' => $dbClient['phone'], 'email' => $dbClient['email'], 'internet' => $dbClient['internet']); if (isset($_POST['save'])) { if (isset($_FILES['file'])) { if (htmlspecialchars($_FILES['file']['name']) !== '') { $file = new files(); $file->upload($_FILES, 'lead', $id); } } if (isset($_POST['name']) && isset($_POST['referralSource']) && isset($_POST['money']) && isset($_POST['status'])) { $refValue = ''; if ($_POST['referralSource'] && $_POST['referralValueOther'] != '') { $refValue = $_POST['referralValueOther']; } else { if ($_POST['referralSource'] == 5 && $_POST['referralValueClient'] > 0) { $refValue = $_POST['referralValueClient']; } } $values = array('name' => $_POST['name'], 'potentialMoney' => $_POST['money'], 'actualMoney' => $_POST['actualMoney'], 'refSource' => $_POST['referralSource'], 'refValue' => $refValue, 'status' => $_POST['status']); $client = array('name' => $_POST['clientName'], 'street' => $_POST['street'], 'zip' => $_POST['zip'], 'city' => $_POST['city'], 'state' => $_POST['state'], 'country' => $_POST['country'], 'phone' => $_POST['phone'], 'email' => $_POST['email'], 'internet' => $_POST['internet']); $this->editLead($values, $id); $clients->editClient($client, $lead['clientId']); $tpl->setNotification('EDIT_SUCCESS', 'success'); } else { $tpl->setNotification('MISSING_FIELDS', 'error'); } } $tpl->assign('client', $client); $tpl->assign('lead', $values); } else { $tpl->display('general.error'); } $client = new clients(); $tpl->assign('status', $this->getStatus()); $tpl->assign('referralSources', $this->getReferralSources()); $tpl->assign('clients', $client->getAll()); $tpl->display('leads.editLead'); }
case "delete_client": $clnt->deleteClient(intval($_GET['delete'])); header("Location: /clients/?a=1{$upage}"); die; break; case "edit_client": $cid = intval($edit); $name = trim(substr($_POST['name_client'], 0, 128)); $link = trim(substr($_POST['link_client'], 0, 255)); if ($_FILES['logo']['name'] != "") { $logo = new CFile($_FILES['logo']); } if ($name && $link && (!$_FILES['logo']['name'] || $logo->size)) { $link = str_replace("http://", "", $link); $link = "http://" . $link; $clnt->editClient($name, $link, $logo, $cid, $error_edit); } else { $error_edit = "Заполнены не все поля"; } if (!$error_edit) { if ($logo) { $logo_tmp = new CFile($_POST['logo_tmp']); $logo_tmp->Delete($logo_tmp->id); } header("Location: /clients/?a=1{$upage}"); die; } break; } $limit = 10; // Сколько на одной странице выдавать
} public function editClient($content) { $id = $content['editAccount']; $uid = $this->returnFieldFromTable("id", "users", "company_id='{$id}'"); $this->query("UPDATE users SET user_name='{$content['user_name']}', user_email='{$content['user_email']}', user_phone='{$content['user_phone']}', \n\t\t\t\tuser_title='{$content['user_title']}' WHERE id='{$uid}'"); $this->query("UPDATE companies SET company_phone='{$content['user_phone']}', company_name='{$content['company_name']}', company_address='{$content['company_address']}', company_address2='{$content['company_address2']}',\n\t\t\t\tcompany_city='{$content['company_city']}', company_state='{$content['company_state']}', company_zip='{$content['company_zip']}' WHERE id='{$id}'"); $json = []; $json['action'] = 'reload'; $json['url'] = '/clients/'; $this->jsonE('success', $json); } } $mod = new clients(); if (isset($_GET['createClient'])) { $mod->createClient(); } else { if (isset($_POST['createAccount'])) { $mod->createAccount($_POST); } else { if (isset($_GET['showClient'])) { $mod->showClient($_GET); } else { if (isset($_POST['editAccount'])) { $mod->editClient($_POST); } else { $mod->main(); } } } }