Commit | Line | Data |
---|---|---|
b814a8b8 SJ |
1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 Polytechnique.org * |
b814a8b8 SJ |
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 | ||
c3d1e6b6 | 24 | class EntrReq extends ProfileValidate |
b814a8b8 SJ |
25 | { |
26 | // {{{ properties | |
27 | ||
28 | public $id; | |
29 | public $name; | |
44365e82 SJ |
30 | public $acronym = null; |
31 | public $url = null; | |
32 | public $email = null; | |
8768e5af | 33 | public $holdingid = null; |
a6dcf7ed | 34 | public $SIREN = null; |
c67b874f | 35 | public $NAF_code = null; |
8768e5af | 36 | public $AX_code = null; |
b814a8b8 | 37 | |
ea9cfc3e SJ |
38 | public $tel = null; |
39 | public $fax = null; | |
40 | public $address = null; | |
b814a8b8 | 41 | |
543b59cc | 42 | public $suggestions; |
bdc3c3d2 | 43 | public $rules = 'Si l\'entreprise est déjà présente sous un autre nom dans la liste des suggestions, remplacer son nom par celui-ci avant de valider. Laisser les autres champs tels quels.'; |
b814a8b8 | 44 | |
e33b29e5 SJ |
45 | public $requireAdmin = false; |
46 | ||
b814a8b8 SJ |
47 | // }}} |
48 | // {{{ constructor | |
49 | ||
26ba053e | 50 | public function __construct(User $_user, Profile $_profile, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_address, $_stamp = 0) |
b814a8b8 | 51 | { |
c3d1e6b6 | 52 | parent::__construct($_user, $_profile, false, 'entreprise', $_stamp); |
543b59cc SJ |
53 | $this->id = $_id; |
54 | $this->name = $_name; | |
55 | $this->acronym = $_acronym; | |
56 | $this->url = $_url; | |
57 | $this->email = $_email; | |
58 | $this->tel = $_tel; | |
59 | $this->fax = $_fax; | |
4d7d27fc | 60 | $this->address = $_address; |
543b59cc | 61 | |
4cf8b468 | 62 | $_name = preg_replace('/[^0-9a-z]/i', ' ', strtolower(replace_accent($_name))); |
543b59cc SJ |
63 | $name = explode(" ", $_name); |
64 | $name_array = array_map("trim", $name); | |
65 | $length = count($name_array); | |
66 | $where = ""; | |
67 | for ($i = 0; $i < $length; $i++) { | |
68 | if (strlen($name_array[$i]) > 2) { | |
69 | if ($where !== "") { | |
70 | $where .= " OR "; | |
71 | } | |
72 | $where .= "name LIKE '%" . $name_array[$i] . "%'"; | |
73 | } | |
74 | } | |
8cc857c7 SJ |
75 | if ($where != '') { |
76 | $res = XDB::iterator('SELECT name | |
77 | FROM profile_job_enum | |
78 | WHERE ' . $where); | |
79 | $this->suggestions = "| "; | |
80 | while ($sug = $res->next()) { | |
81 | $this->suggestions .= $sug['name'] . " | "; | |
82 | } | |
543b59cc | 83 | } |
b814a8b8 SJ |
84 | } |
85 | ||
86 | // }}} | |
87 | // {{{ function formu() | |
88 | ||
89 | public function formu() | |
90 | { | |
91 | return 'include/form.valid.entreprises.tpl'; | |
92 | } | |
93 | ||
94 | // }}} | |
95 | // {{{ function editor() | |
96 | ||
97 | public function editor() | |
98 | { | |
99 | return 'include/form.valid.edit-entreprises.tpl'; | |
100 | } | |
101 | ||
102 | // }}} | |
103 | // {{{ function handle_editor() | |
104 | ||
105 | protected function handle_editor() | |
106 | { | |
a6dcf7ed | 107 | foreach (array('name', 'acronym', 'url', 'email', 'SIREN', 'NAF_code', 'tel', 'fax', 'address') as $field) { |
44365e82 | 108 | $this->$field = (Env::t($field) == '' ? null : Env::t($field)); |
b814a8b8 | 109 | } |
44365e82 SJ |
110 | foreach (array('AX_code', 'holdingid') as $field) { |
111 | $this->$field = (Env::i($field) == 0 ? null : Env::i($field)); | |
36270bc2 | 112 | } |
44365e82 | 113 | |
36270bc2 | 114 | return true; |
b814a8b8 SJ |
115 | } |
116 | ||
117 | // }}} | |
118 | // {{{ function _mail_subj | |
119 | ||
120 | protected function _mail_subj() | |
121 | { | |
2381efd0 | 122 | return '[Polytechnique.org/Entreprises] Demande d\'ajout d\'une entreprise'; |
b814a8b8 SJ |
123 | } |
124 | ||
125 | // }}} | |
126 | // {{{ function _mail_body | |
127 | ||
128 | protected function _mail_body($isok) | |
129 | { | |
130 | if ($isok) { | |
131 | return " L'entreprise " . $this->name . " vient d'être ajoutée à ta fiche."; | |
132 | } else { | |
f4b0bbda | 133 | return ' La demande que tu avais faite pour l\'entreprise ' . $this->name . ' a été refusée.'; |
b814a8b8 SJ |
134 | } |
135 | } | |
136 | ||
137 | // }}} | |
138 | // {{{ function commit() | |
139 | ||
140 | public function commit() | |
141 | { | |
142 | $res = XDB::query('SELECT id | |
143 | FROM profile_job_enum | |
144 | WHERE name = {?}', | |
145 | $this->name); | |
146 | if ($res->numRows() != 1) { | |
a6dcf7ed TM |
147 | XDB::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, SIREN_code, NAF_code, AX_code) |
148 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
b814a8b8 | 149 | $this->name, $this->acronym, $this->url, $this->email, |
a6dcf7ed | 150 | $this->holdingid, $this->SIREN, $this->NAF_code, $this->AX_code); |
e0ee3120 | 151 | |
b814a8b8 | 152 | $jobid = XDB::insertId(); |
0b6c8b36 SJ |
153 | $phone = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 0, |
154 | 'type' => 'fixed', 'display' => $this->tel, 'pub' => 'public')); | |
155 | $fax = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 1, | |
156 | 'type' => 'fax', 'display' => $this->fax, 'pub' => 'public')); | |
ea9cfc3e | 157 | $address = new Address(array('jobid' => $jobid, 'type' => Address::LINK_COMPANY, 'text' => $this->address)); |
0b6c8b36 SJ |
158 | $phone->save(); |
159 | $fax->save(); | |
eb54852e | 160 | $address->save(); |
b814a8b8 SJ |
161 | } else { |
162 | $jobid = $res->fetchOneCell(); | |
b814a8b8 | 163 | } |
eb54852e | 164 | |
a38c0777 SJ |
165 | XDB::execute('UPDATE profile_job |
166 | SET jobid = {?} | |
167 | WHERE pid = {?} AND id = {?}', | |
168 | $jobid, $this->profile->id(), $this->id); | |
169 | if (XDB::affectedRows() == 0) { | |
170 | return XDB::execute('INSERT INTO profile_job (jobid, pid, id) | |
171 | VALUES ({?}, {?}, {?})', | |
172 | $jobid, $this->profile->id(), $this->id); | |
173 | } | |
174 | return true; | |
b814a8b8 SJ |
175 | } |
176 | ||
177 | // }}} | |
178 | } | |
179 | ||
180 | // }}} | |
181 | ||
448c8cdc | 182 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
b814a8b8 | 183 | ?> |