Allows users to add a new entreprise.
[platal.git] / include / validations / entreprises.inc.php
CommitLineData
b814a8b8
SJ
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
24class 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 //TODO: addresses
41
42 // }}}
43 // {{{ constructor
44
45 public function __construct(User &$_user, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_stamp = 0)
46 {
47 parent::__construct($_user, true, 'entreprise', $_stamp);
48 $this->id = $_id;
49 $this->name = $_name;
50 $this->acronym = $_acronym;
51 $this->url = $_url;
52 $this->email = $_email;
53 $this->tel = $_tel;
54 $this->fax = $_fax;
55 }
56
57 // }}}
58 // {{{ function formu()
59
60 public function formu()
61 {
62 return 'include/form.valid.entreprises.tpl';
63 }
64
65 // }}}
66 // {{{ function editor()
67
68 public function editor()
69 {
70 return 'include/form.valid.edit-entreprises.tpl';
71 }
72
73 // }}}
74 // {{{ function handle_editor()
75
76 protected function handle_editor()
77 {
78 if (Env::has('holdingid')) {
79 $this->holdingid = trim(Env::v('holdingid'));
80 }
81 if (Env::has('name')) {
82 $this->name = trim(Env::v('name'));
83 if (Env::has('acronym')) {
84 $this->acronym = trim(Env::v('acronym'));
85 if (Env::has('url')) {
86 $this->url = trim(Env::v('url'));
87 if (Env::has('NAF_code')) {
88 $this->NAF_code = trim(Env::v('NAF_code'));
89 if (Env::has('AX_code')) {
90 $this->AX_code = trim(Env::v('AX_code'));
91 return true;
92 }
93 }
94 }
95 }
96 }
97 return false;
98 }
99
100 // }}}
101 // {{{ function _mail_subj
102
103 protected function _mail_subj()
104 {
105 return "[Polytechnique.org/Entreprises] Demande d'ajout d'une entreprise : " . $this->name;
106 }
107
108 // }}}
109 // {{{ function _mail_body
110
111 protected function _mail_body($isok)
112 {
113 if ($isok) {
114 return " L'entreprise " . $this->name . " vient d'être ajoutée à ta fiche.";
115 } else {
116 return " La demande que tu avais faite pour l'entreprise " . $this->name .
117 " a été refusée, car elle figure déjà dans notre base.";
118 }
119 }
120
121 // }}}
122 // {{{ function commit()
123
124 public function commit()
125 {
126 $res = XDB::query('SELECT id
127 FROM profile_job_enum
128 WHERE name = {?}',
129 $this->name);
130 if ($res->numRows() != 1) {
131 require_once("profil.func.inc.php");
132
133 XDB::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, NAF_code, AX_code)
134 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
135 $this->name, $this->acronym, $this->url, $this->email,
136 $this->holdingid, $this->NAF_code, $this->AX_code);
137 $jobid = XDB::insertId();
138 $display_tel = format_display_number($this->tel, $error_tel);
139 $display_fax =format_display_number($this->fax, $error_fax);
140 XDB::execute('INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type,
141 search_tel, display_tel, pub)
142 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}),
143 ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
144 $jobid, 'hq', $this->id, 0, 'fixed', format_phone_number($this->tel), $display_tel, 'public',
145 $jobid, 'hq', $this->id, 1, 'fax', format_phone_number($this->fax), $display_fax, 'public');
146 } else {
147 $jobid = $res->fetchOneCell();
148 $success = true;
149 }
150 return XDB::execute('UPDATE profile_job
151 SET jobid = {?}
152 WHERE uid = {?} AND id = {?}',
153 $jobid, $this->user->id(), $this->id);
154 }
155
156 // }}}
157}
158
159// }}}
160
161// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
162?>