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
46 public function __construct(User
&$_user, Profile
&$_profile, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_address, $_stamp = 0)
48 parent
::__construct($_user, $_profile, false
, 'entreprise', $_stamp);
51 $this->acronym
= $_acronym;
53 $this->email
= $_email;
56 $this->address
= $_address;
58 $_name = preg_replace('/[^0-9a-z]/i', ' ', strtolower(replace_accent($_name)));
59 $name = explode(" ", $_name);
60 $name_array = array_map("trim", $name);
61 $length = count($name_array);
63 for ($i = 0; $i < $length; $i++
) {
64 if (strlen($name_array[$i]) > 2) {
68 $where .= "name LIKE '%" . $name_array[$i] . "%'";
71 $res = XDB
::iterator('SELECT name
74 $this->suggestions
= "| ";
75 while ($sug = $res->next()) {
76 $this->suggestions
.= $sug['name'] . " | ";
81 // {{{ function formu()
83 public function formu()
85 return 'include/form.valid.entreprises.tpl';
89 // {{{ function editor()
91 public function editor()
93 return 'include/form.valid.edit-entreprises.tpl';
97 // {{{ function handle_editor()
99 protected function handle_editor()
101 if (Env
::has('name')) {
102 $this->name
= Env
::t('name');
104 if (Env
::has('acronym')) {
105 $this->acronym
= Env
::t('acronym');
107 if (Env
::has('url')) {
108 $this->url
= Env
::t('url');
110 if (Env
::has('email')) {
111 $this->email
= Env
::t('email');
113 if (Env
::has('holdingid')) {
114 $this->holdingid
= Env
::i('holdingid');
116 if (Env
::has('NAF_code')) {
117 $this->NAF_code
= Env
::t('NAF_code');
119 if (Env
::has('AX_code')) {
120 $this->AX_code
= Env
::i('AX_code');
122 if (Env
::has('address')) {
123 $this->address
['text'] = Env
::t('address');
125 if (Env
::has('tel')) {
126 $this->tel
= Env
::t('tel');
128 if (Env
::has('fax')) {
129 $this->fax
= Env
::t('fax');
135 // {{{ function _mail_subj
137 protected function _mail_subj()
139 return "[Polytechnique.org/Entreprises] Demande d'ajout d'une entreprise : " . $this->name
;
143 // {{{ function _mail_body
145 protected function _mail_body($isok)
148 return " L'entreprise " . $this->name
. " vient d'être ajoutée à ta fiche.";
150 return " La demande que tu avais faite pour l'entreprise " . $this->name
.
151 " a été refusée, car elle figure déjà dans notre base.";
156 // {{{ function commit()
158 public function commit()
160 // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
162 $res = XDB
::query('SELECT id
163 FROM profile_job_enum
166 if ($res->numRows() != 1) {
167 require_once 'profil.func.inc.php';
168 require_once 'geocoding.inc.php';
170 XDB
::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, NAF_code, AX_code)
171 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
172 $this->name
, $this->acronym
, $this->url
, $this->email
,
173 $this->holdingid
, $this->NAF_code
, $this->AX_code
);
175 $jobid = XDB
::insertId();
176 $display_tel = format_display_number($this->tel
, $error_tel);
177 $display_fax = format_display_number($this->fax
, $error_fax);
178 XDB
::execute("INSERT INTO profile_phones (pid, link_type, link_id, tel_id, tel_type,
179 search_tel, display_tel, pub)
180 VALUES ({?}, 'hq', 0, 0, 'fixed', {?}, {?}, 'public'),
181 ({?}, 'hq', 0, 1, 'fax', {?}, {?}, 'public')",
182 $jobid, format_phone_number($this->tel
), $display_tel,
183 $jobid, format_phone_number($this->fax
), $display_fax);
185 $gmapsGeocoder = new GMapsGeocoder();
186 $address = $gmapsGeocoder->getGeocodedAddress($this->address
);
187 Geocoder
::getAreaId($address, 'administrativeArea');
188 Geocoder
::getAreaId($address, 'subAdministrativeArea');
189 Geocoder
::getAreaId($address, 'locality');
190 XDB
::execute("INSERT INTO profile_addresses (jobid, type, id, accuracy,
191 text, postalText, postalCode, localityId,
192 subAdministrativeAreaId, administrativeAreaId,
193 countryId, latitude, longitude, updateTime,
194 north, south, east, west)
195 VALUES ({?}, 'hq', 0, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
196 {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?})",
197 $jobid, $this->address
['accuracy'], $this->address
['text'], $this->address
['postalText'],
198 $this->address
['postalCode'], $this->address
['localityId'],
199 $this->address
['subAdministrativeAreaId'], $this->address
['administrativeAreaId'],
200 $this->address
['countryId'], $this->address
['latitude'], $this->address
['longitude'],
201 $this->address
['updateTime'], $this->address
['north'], $this->address
['south'],
202 $this->address
['east'], $this->address
['west']);
204 $jobid = $res->fetchOneCell();
206 XDB
::execute('UPDATE profile_job
208 WHERE pid = {?} AND id = {?}',
209 $jobid, $this->profile
->id(), $this->id
);
210 if (XDB
::affectedRows() == 0) {
211 return XDB
::execute('INSERT INTO profile_job (jobid, pid, id)
212 VALUES ({?}, {?}, {?})',
213 $jobid, $this->profile
->id(), $this->id
);
223 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: