| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | // {{{ class EntrReq |
| 23 | |
| 24 | class EntrReq extends Validate |
| 25 | { |
| 26 | // {{{ properties |
| 27 | |
| 28 | public $id; |
| 29 | public $name; |
| 30 | public $acronym; |
| 31 | public $url; |
| 32 | public $email; |
| 33 | public $holdingid; |
| 34 | public $NAF_code; |
| 35 | public $AX_code; |
| 36 | |
| 37 | public $tel; |
| 38 | public $fax; |
| 39 | |
| 40 | public $suggestions; |
| 41 | //TODO: addresses |
| 42 | |
| 43 | // }}} |
| 44 | // {{{ constructor |
| 45 | |
| 46 | public function __construct(User &$_user, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_stamp = 0) |
| 47 | { |
| 48 | parent::__construct($_user, false, 'entreprise', $_stamp); |
| 49 | $this->id = $_id; |
| 50 | $this->name = $_name; |
| 51 | $this->acronym = $_acronym; |
| 52 | $this->url = $_url; |
| 53 | $this->email = $_email; |
| 54 | $this->tel = $_tel; |
| 55 | $this->fax = $_fax; |
| 56 | |
| 57 | $_name = str_replace(array("&", "(", ")", "-", "_", ",", ";", ".", ":", "/", "\\", "\'", "\""), " ", $_name); |
| 58 | $name = explode(" ", $_name); |
| 59 | $name_array = array_map("trim", $name); |
| 60 | $length = count($name_array); |
| 61 | $where = ""; |
| 62 | for ($i = 0; $i < $length; $i++) { |
| 63 | if (strlen($name_array[$i]) > 2) { |
| 64 | if ($where !== "") { |
| 65 | $where .= " OR "; |
| 66 | } |
| 67 | $where .= "name LIKE '%" . $name_array[$i] . "%'"; |
| 68 | } |
| 69 | } |
| 70 | $res = XDB::iterator("SELECT name |
| 71 | FROM profile_job_enum |
| 72 | WHERE " |
| 73 | . $where); |
| 74 | $this->suggestions = "| "; |
| 75 | while ($sug = $res->next()) { |
| 76 | var_dump($sug); |
| 77 | $this->suggestions .= $sug['name'] . " | "; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // }}} |
| 82 | // {{{ function formu() |
| 83 | |
| 84 | public function formu() |
| 85 | { |
| 86 | return 'include/form.valid.entreprises.tpl'; |
| 87 | } |
| 88 | |
| 89 | // }}} |
| 90 | // {{{ function editor() |
| 91 | |
| 92 | public function editor() |
| 93 | { |
| 94 | return 'include/form.valid.edit-entreprises.tpl'; |
| 95 | } |
| 96 | |
| 97 | // }}} |
| 98 | // {{{ function handle_editor() |
| 99 | |
| 100 | protected function handle_editor() |
| 101 | { |
| 102 | if (Env::has('holdingid')) { |
| 103 | $this->holdingid = trim(Env::v('holdingid')); |
| 104 | } |
| 105 | if (Env::has('name')) { |
| 106 | $this->name = trim(Env::v('name')); |
| 107 | if (Env::has('acronym')) { |
| 108 | $this->acronym = trim(Env::v('acronym')); |
| 109 | if (Env::has('url')) { |
| 110 | $this->url = trim(Env::v('url')); |
| 111 | if (Env::has('NAF_code')) { |
| 112 | $this->NAF_code = trim(Env::v('NAF_code')); |
| 113 | if (Env::has('AX_code')) { |
| 114 | $this->AX_code = trim(Env::v('AX_code')); |
| 115 | return true; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | // }}} |
| 125 | // {{{ function _mail_subj |
| 126 | |
| 127 | protected function _mail_subj() |
| 128 | { |
| 129 | return "[Polytechnique.org/Entreprises] Demande d'ajout d'une entreprise : " . $this->name; |
| 130 | } |
| 131 | |
| 132 | // }}} |
| 133 | // {{{ function _mail_body |
| 134 | |
| 135 | protected function _mail_body($isok) |
| 136 | { |
| 137 | if ($isok) { |
| 138 | return " L'entreprise " . $this->name . " vient d'être ajoutée à ta fiche."; |
| 139 | } else { |
| 140 | return " La demande que tu avais faite pour l'entreprise " . $this->name . |
| 141 | " a été refusée, car elle figure déjà dans notre base."; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // }}} |
| 146 | // {{{ function commit() |
| 147 | |
| 148 | public function commit() |
| 149 | { |
| 150 | $res = XDB::query('SELECT id |
| 151 | FROM profile_job_enum |
| 152 | WHERE name = {?}', |
| 153 | $this->name); |
| 154 | if ($res->numRows() != 1) { |
| 155 | require_once("profil.func.inc.php"); |
| 156 | |
| 157 | XDB::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, NAF_code, AX_code) |
| 158 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', |
| 159 | $this->name, $this->acronym, $this->url, $this->email, |
| 160 | $this->holdingid, $this->NAF_code, $this->AX_code); |
| 161 | $jobid = XDB::insertId(); |
| 162 | $display_tel = format_display_number($this->tel, $error_tel); |
| 163 | $display_fax =format_display_number($this->fax, $error_fax); |
| 164 | XDB::execute('INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, |
| 165 | search_tel, display_tel, pub) |
| 166 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}), |
| 167 | ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', |
| 168 | $jobid, 'hq', $this->id, 0, 'fixed', format_phone_number($this->tel), $display_tel, 'public', |
| 169 | $jobid, 'hq', $this->id, 1, 'fax', format_phone_number($this->fax), $display_fax, 'public'); |
| 170 | } else { |
| 171 | $jobid = $res->fetchOneCell(); |
| 172 | $success = true; |
| 173 | } |
| 174 | return XDB::execute('UPDATE profile_job |
| 175 | SET jobid = {?} |
| 176 | WHERE uid = {?} AND id = {?}', |
| 177 | $jobid, $this->user->id(), $this->id); |
| 178 | } |
| 179 | |
| 180 | // }}} |
| 181 | } |
| 182 | |
| 183 | // }}} |
| 184 | |
| 185 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 186 | ?> |