2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 class EntrReq
extends ProfileValidate
33 public $holdingid = null
;
34 public $NAF_code = null
;
35 public $AX_code = null
;
42 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.';
47 public function __construct(User
&$_user, Profile
&$_profile, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_address, $_stamp = 0)
49 parent
::__construct($_user, $_profile, false
, 'entreprise', $_stamp);
52 $this->acronym
= $_acronym;
54 $this->email
= $_email;
57 $this->address
= $_address;
59 $_name = preg_replace('/[^0-9a-z]/i', ' ', strtolower(replace_accent($_name)));
60 $name = explode(" ", $_name);
61 $name_array = array_map("trim", $name);
62 $length = count($name_array);
64 for ($i = 0; $i < $length; $i++
) {
65 if (strlen($name_array[$i]) > 2) {
69 $where .= "name LIKE '%" . $name_array[$i] . "%'";
73 $res = XDB
::iterator('SELECT name
76 $this->suggestions
= "| ";
77 while ($sug = $res->next()) {
78 $this->suggestions
.= $sug['name'] . " | ";
84 // {{{ function formu()
86 public function formu()
88 return 'include/form.valid.entreprises.tpl';
92 // {{{ function editor()
94 public function editor()
96 return 'include/form.valid.edit-entreprises.tpl';
100 // {{{ function handle_editor()
102 protected function handle_editor()
104 if (Env
::has('name')) {
105 $this->name
= Env
::t('name');
107 if (Env
::has('acronym')) {
108 $this->acronym
= Env
::t('acronym');
110 if (Env
::has('url')) {
111 $this->url
= Env
::t('url');
113 if (Env
::has('email')) {
114 $this->email
= Env
::t('email');
116 if (Env
::has('holdingid')) {
117 $this->holdingid
= Env
::i('holdingid');
119 if (Env
::has('NAF_code')) {
120 $this->NAF_code
= Env
::t('NAF_code');
122 if (Env
::has('AX_code')) {
123 $this->AX_code
= Env
::i('AX_code');
125 if (Env
::has('address')) {
126 $this->address
['text'] = Env
::t('address');
128 if (Env
::has('tel')) {
129 $this->tel
= Env
::t('tel');
131 if (Env
::has('fax')) {
132 $this->fax
= Env
::t('fax');
138 // {{{ function _mail_subj
140 protected function _mail_subj()
142 return '[Polytechnique.org/Entreprises] Demande d\'ajout d\'une entreprise';
146 // {{{ function _mail_body
148 protected function _mail_body($isok)
151 return " L'entreprise " . $this->name
. " vient d'être ajoutée à ta fiche.";
153 return " La demande que tu avais faite pour l'entreprise " . $this->name
.
154 " a été refusée, car elle figure déjà dans notre base.";
159 // {{{ function commit()
161 public function commit()
163 $res = XDB
::query('SELECT id
164 FROM profile_job_enum
167 if ($res->numRows() != 1) {
168 XDB
::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, NAF_code, AX_code)
169 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
170 $this->name
, $this->acronym
, $this->url
, $this->email
,
171 $this->holdingid
, $this->NAF_code
, $this->AX_code
);
173 $jobid = XDB
::insertId();
174 $phone = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 0,
175 'type' => 'fixed', 'display' => $this->tel
, 'pub' => 'public'));
176 $fax = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 1,
177 'type' => 'fax', 'display' => $this->fax
, 'pub' => 'public'));
178 $address = new Address(array('jobid' => $jobid, 'type' => Address
::LINK_COMPANY
, 'text' => $this->address
));
183 $jobid = $res->fetchOneCell();
186 XDB
::execute('UPDATE profile_job
188 WHERE pid = {?} AND id = {?}',
189 $jobid, $this->profile
->id(), $this->id
);
190 if (XDB
::affectedRows() == 0) {
191 return XDB
::execute('INSERT INTO profile_job (jobid, pid, id)
192 VALUES ({?}, {?}, {?})',
193 $jobid, $this->profile
->id(), $this->id
);
203 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: