From b814a8b87885dcaca0d2d9820205d69f75422b1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Mon, 10 Nov 2008 01:37:54 +0100 Subject: [PATCH] Allows users to add a new entreprise. --- htdocs/javascript/profile.js | 10 +- include/validations.inc.php | 2 +- include/validations/entreprises.inc.php | 162 ++++++++++++++++++++++ modules/profile.php | 4 +- modules/profile/general.inc.php | 14 +- modules/profile/jobs.inc.php | 49 +++++-- modules/profile/page.inc.php | 26 ++-- templates/include/form.valid.edit-entreprises.tpl | 42 ++++++ templates/include/form.valid.entreprises.tpl | 66 +++++++++ templates/profile/jobs.job.tpl | 68 ++++++++- upgrade/newdirectory-0.0.1/11_jobs.sql | 1 + upgrade/newdirectory-0.0.1/12_secteurs.sql | 3 + 12 files changed, 400 insertions(+), 47 deletions(-) create mode 100644 include/validations/entreprises.inc.php create mode 100644 templates/include/form.valid.edit-entreprises.tpl create mode 100644 templates/include/form.valid.entreprises.tpl diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 64dc174..f8c3fbc 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -517,10 +517,10 @@ function updateJobSousSecteur(nb, id, pref, sel) Ajax.update_html(id + '_sss_secteur', 'profile/ajax/ssecteur/' + nb + '/' + ssecteur + '/' + sel); } -function displayAllSector() +function displayAllSector(id) { - $('.sector_text').remove(); - $('.sector').show(); + $('.sector_text_' + id).remove(); + $('.sector_' + id).show(); } function makeAddJob(id) @@ -542,6 +542,10 @@ function addJob() $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); } +function addEntreprise(id) +{ + $('.entreprise_' + id).toggle(); +} // Skills diff --git a/include/validations.inc.php b/include/validations.inc.php index 97e1b15..9b3e1f7 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -87,7 +87,7 @@ abstract class Validate $this->type = $_type; $res = XDB::query("SELECT promo_display AS promo FROM profile_display - WHERE uid={?}", $_uid); + WHERE uid={?}", $this->user->id()); $this->promo = $res->fetchOneCell(); } diff --git a/include/validations/entreprises.inc.php b/include/validations/entreprises.inc.php new file mode 100644 index 0000000..2e1cd9a --- /dev/null +++ b/include/validations/entreprises.inc.php @@ -0,0 +1,162 @@ +id = $_id; + $this->name = $_name; + $this->acronym = $_acronym; + $this->url = $_url; + $this->email = $_email; + $this->tel = $_tel; + $this->fax = $_fax; + } + + // }}} + // {{{ function formu() + + public function formu() + { + return 'include/form.valid.entreprises.tpl'; + } + + // }}} + // {{{ function editor() + + public function editor() + { + return 'include/form.valid.edit-entreprises.tpl'; + } + + // }}} + // {{{ function handle_editor() + + protected function handle_editor() + { + if (Env::has('holdingid')) { + $this->holdingid = trim(Env::v('holdingid')); + } + if (Env::has('name')) { + $this->name = trim(Env::v('name')); + if (Env::has('acronym')) { + $this->acronym = trim(Env::v('acronym')); + if (Env::has('url')) { + $this->url = trim(Env::v('url')); + if (Env::has('NAF_code')) { + $this->NAF_code = trim(Env::v('NAF_code')); + if (Env::has('AX_code')) { + $this->AX_code = trim(Env::v('AX_code')); + return true; + } + } + } + } + } + return false; + } + + // }}} + // {{{ function _mail_subj + + protected function _mail_subj() + { + return "[Polytechnique.org/Entreprises] Demande d'ajout d'une entreprise : " . $this->name; + } + + // }}} + // {{{ function _mail_body + + protected function _mail_body($isok) + { + if ($isok) { + return " L'entreprise " . $this->name . " vient d'être ajoutée à ta fiche."; + } else { + return " La demande que tu avais faite pour l'entreprise " . $this->name . + " a été refusée, car elle figure déjà dans notre base."; + } + } + + // }}} + // {{{ function commit() + + public function commit() + { + $res = XDB::query('SELECT id + FROM profile_job_enum + WHERE name = {?}', + $this->name); + if ($res->numRows() != 1) { + require_once("profil.func.inc.php"); + + XDB::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, NAF_code, AX_code) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', + $this->name, $this->acronym, $this->url, $this->email, + $this->holdingid, $this->NAF_code, $this->AX_code); + $jobid = XDB::insertId(); + $display_tel = format_display_number($this->tel, $error_tel); + $display_fax =format_display_number($this->fax, $error_fax); + XDB::execute('INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, + search_tel, display_tel, pub) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}), + ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + $jobid, 'hq', $this->id, 0, 'fixed', format_phone_number($this->tel), $display_tel, 'public', + $jobid, 'hq', $this->id, 1, 'fax', format_phone_number($this->fax), $display_fax, 'public'); + } else { + $jobid = $res->fetchOneCell(); + $success = true; + } + return XDB::execute('UPDATE profile_job + SET jobid = {?} + WHERE uid = {?} AND id = {?}', + $jobid, $this->user->id(), $this->id); + } + + // }}} +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/profile.php b/modules/profile.php index 21b3ed9..6fe8ad3 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -464,8 +464,8 @@ class ProfileModule extends PLModule $page->assign('i', $id); $page->assign('job', array()); $page->assign('new', true); - $res = XDB::query("SELECT id, label - FROM emploi_secteur"); + $res = XDB::query("SELECT id, name AS label + FROM profile_job_sector_enum"); $page->assign('secteurs', $res->fetchAllAssoc()); $res = XDB::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title FROM fonctions_def diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 3f13936..ecb18b3 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -82,9 +82,7 @@ class ProfileSearchName implements ProfileSetting class ProfileEdu implements ProfileSetting { - public function __construct() - { - } + public function __construct(){} static function sortByGradYear($line1, $line2) { $a = (int) $line1['grad_year']; @@ -142,14 +140,12 @@ class ProfileEdu implements ProfileSetting } } } - } class ProfileEmailDirectory implements ProfileSetting { - public function __construct() - { - } + public function __construct(){} + public function save(ProfilePage &$page, $field, $value){} public function value(ProfilePage &$page, $field, $value, &$success) { @@ -169,10 +165,6 @@ class ProfileEmailDirectory implements ProfileSetting } return $value; } - - public function save(ProfilePage &$page, $field, $value) - { - } } class ProfileNetworking implements ProfileSetting diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 7983f8f..e392d46 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -42,7 +42,7 @@ class ProfileJob extends ProfileGeoloc 'pub' => array('pub', 'w_email_pub')); } - private function cleanJob(ProfilePage &$page,$jobid, array &$job, &$success) + private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success) { $success = true; foreach ($this->checks as $obj=>&$fields) { @@ -61,7 +61,7 @@ class ProfileJob extends ProfileGeoloc } } } - if (!isset($job['sss_secteur_name'])) { + if (!$job['sss_secteur_name']) { $res = XDB::query("SELECT name FROM profile_job_subsubsector_enum WHERE id = {?}", @@ -79,14 +79,16 @@ class ProfileJob extends ProfileGeoloc list($job['secteur'], $job['ss_secteur'], $job['sss_secteur']) = $res->fetchOneRow(); } } - if (!isset($job['jobid'])) { + if ($job['name']) { $res = XDB::query("SELECT id FROM profile_job_enum WHERE name = {?}", $job['name']); if ($res->numRows() != 1) { - $success = false; - $job['name_error'] = true; + $user = S::user(); + $req = new EntrReq($user, $jobid, $job['name'], $job['acronym'], $job['hq_web'], $job['hq_email'], $job['hq_tel'], $job['hq_fax']); + $req->submit(); + $job['jobid'] = null; } else { $job['jobid'] = $res->fetchOneCell(); } @@ -107,6 +109,10 @@ class ProfileJob extends ProfileGeoloc public function value(ProfilePage &$page, $field, $value, &$success) { + require_once('validations.inc.php'); + $entreprise = Validate::get_typed_requests(S::i('uid'), 'entreprise'); + $entr_val = 0; + $init = false; if (is_null($value)) { $value = $page->values['jobs']; @@ -114,7 +120,12 @@ class ProfileJob extends ProfileGeoloc } $success = true; foreach ($value as $key=>&$job) { - if (@$job['removed'] || !trim($job['name'])) { + $job['name'] = trim($job['name']); + if (!$job['name']) { + $job['tmp_name'] = $entreprise[$entr_val]->name; + $entr_val ++; + } + if (@$job['removed']) { unset($value[$key]); } } @@ -134,25 +145,33 @@ class ProfileJob extends ProfileGeoloc public function save(ProfilePage &$page, $field, $value) { require_once('profil.func.inc.php'); + require_once('validations.inc.php'); + XDB::execute("DELETE FROM profile_job WHERE uid = {?}", S::i('uid')); XDB::execute("DELETE FROM profile_phones WHERE uid = {?} AND link_type = 'pro'", S::i('uid')); - $i = 0; - foreach ($value as $jobid=>&$job) { + foreach ($value as $id=>&$job) { if ($job['w_email'] == "new@example.org") { $job['w_email'] = $job['w_email_new']; } - XDB::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid, - subsubsectorid, email, url, pub, email_pub, jobid) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", - S::i('uid'), $i, $job['fonction'], $job['description'], $job['secteur'], $job['ss_secteur'], - $job['sss_secteur'], $job['w_email'], $job['w_web'], $job['pub'], $job['w_email_pub'], $job['jobid']); - $profiletel = new ProfilePhones('pro', $jobid); + if ($job['jobid']) { + XDB::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid, + subsubsectorid, email, url, pub, email_pub, jobid) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", + S::i('uid'), $id, $job['fonction'], $job['description'], $job['secteur'], $job['ss_secteur'], + $job['sss_secteur'], $job['w_email'], $job['w_web'], $job['pub'], $job['w_email_pub'], $job['jobid']); + } else { + XDB::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid, + subsubsectorid, email, url, pub, email_pub) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", + S::i('uid'), $id, $job['fonction'], $job['description'], $job['secteur'], $job['ss_secteur'], + $job['sss_secteur'], $job['w_email'], $job['w_web'], $job['pub'], $job['w_email_pub']); + } + $profiletel = new ProfilePhones('pro', $id); $profiletel->saveTels('tel', $job['w_tel']); - $i++; } } } diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index d852b5b..6dabf8f 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -119,15 +119,21 @@ class ProfilePhones implements ProfileSetting { private $tel; private $pub; + protected $id; protected $link_type; protected $link_id; - public function __construct($type, $id) + public function __construct($type, $link_id, $id = 0) { + if ($id != 0) { + $this->id = $id; + } else { + $this->id = S::i('uid'); + } $this->tel = new ProfileTel(); $this->pub = new ProfilePub(); $this->link_type = $type; - $this->link_id = $id; + $this->link_id = $link_id; } public function value(ProfilePage &$page, $field, $value, &$success) @@ -135,11 +141,11 @@ class ProfilePhones implements ProfileSetting $success = true; if (is_null($value) || !is_array($value)) { $value = array(); - $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment - FROM profile_phones AS t - WHERE t.uid = {?} AND t.link_type = {?} - ORDER BY t.tel_id", - S::v('uid'), $this->link_type); + $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment + FROM profile_phones AS t + WHERE t.uid = {?} AND t.link_type = {?} + ORDER BY t.tel_id", + $this->id, $this->link_type); $value = $res->fetchAllAssoc(); } foreach ($value as $key=>&$phone) { @@ -172,8 +178,8 @@ class ProfilePhones implements ProfileSetting search_tel, display_tel, pub, comment) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", - S::i('uid'), $this->link_type, $this->link_id, $telid, $phone['type'], - format_phone_number($phone['tel']), $phone['tel'], $phone['pub'], $phone['comment']); + $this->id, $this->link_type, $this->link_id, $telid, $phone['type'], + format_phone_number($phone['tel']), $phone['tel'], $phone['pub'], $phone['comment']); } } @@ -181,7 +187,7 @@ class ProfilePhones implements ProfileSetting { XDB::execute("DELETE FROM profile_phones WHERE uid = {?} AND link_type = {?} AND link_id = {?}", - S::i('uid'), $this->link_type, $this->link_id); + $this->id, $this->link_type, $this->link_id); $this->saveTels($field, $value); } diff --git a/templates/include/form.valid.edit-entreprises.tpl b/templates/include/form.valid.edit-entreprises.tpl new file mode 100644 index 0000000..89b19e0 --- /dev/null +++ b/templates/include/form.valid.edit-entreprises.tpl @@ -0,0 +1,42 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +Nom : +
+Acronyme : +
+Site web : +
+Email : +
+Holding : +
+Code NAF : +
+Code AX : +
+Téléphone : +
+Fax : +
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/include/form.valid.entreprises.tpl b/templates/include/form.valid.entreprises.tpl new file mode 100644 index 0000000..f822feb --- /dev/null +++ b/templates/include/form.valid.entreprises.tpl @@ -0,0 +1,66 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + + + + Nom : + {$valid->name} + + + Acronyme : + {$valid->acronym} + + + Site web : + {$valid->url} + + + Email : + {$valid->email} + + + Holding : + {$valid->holdingid} + + + Code NAF : + {$valid->NAF_code} + + + Code AX : + {$valid->AX_code} + + + Téléphone : + {$valid->tel} + + + Fax : + {$valid->fax} + + + + Bien remplir tous les champs, en particulier les codes NAF et AX ! + + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/jobs.job.tpl b/templates/profile/jobs.job.tpl index b12d298..84ce1d1 100644 --- a/templates/profile/jobs.job.tpl +++ b/templates/profile/jobs.job.tpl @@ -22,6 +22,9 @@ {assign var=jobid value="job_`$i`"} {assign var=jobpref value="jobs[`$i`]"} +{assign var=sector_text value="sector_text_"|cat:$i} +{assign var=sector value="sector_"|cat:$i} +{assign var=entreprise value="entreprise_"|cat:$i}
@@ -53,23 +56,78 @@ Nom de l'entreprise + {if $job.tmp_name}{$job.tmp_name} (en cours de validation){else} + {/if} + + + {if !$job.tmp_name} + + + Si ton entreprise ne figure pas dans la liste, + clique ici et complète les informations la concernant. + + + {/if} + + Acronyme + + + + + + Page Web + + + + + + Email de contact + + + + + + + Téléphone + + + + + + Fax + + Ta place dans l'entreprise - + Secteur d'activité - {icon name="table" title="Tous les secteurs"} + {icon name="table" title="Tous les secteurs"} - + Secteur d'activité - + - + diff --git a/upgrade/newdirectory-0.0.1/11_jobs.sql b/upgrade/newdirectory-0.0.1/11_jobs.sql index 0830cee..8505fb8 100644 --- a/upgrade/newdirectory-0.0.1/11_jobs.sql +++ b/upgrade/newdirectory-0.0.1/11_jobs.sql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS profile_job_enum ( name VARCHAR(255) NOT NULL DEFAULT '', acronym VARCHAR(255) NOT NULL DEFAULT '', url VARCHAR(255) NOT NULL DEFAULT '', + email VARCHAR(255) NOT NULL DEFAULT '', holdingid INT(6) UNSIGNED DEFAULT NULL, NAF_code CHAR(5) NOT NULL DEFAULT '', AX_code BIGINT(10) UNSIGNED NOT NULL, diff --git a/upgrade/newdirectory-0.0.1/12_secteurs.sql b/upgrade/newdirectory-0.0.1/12_secteurs.sql index 9ed21a6..f659ddb 100644 --- a/upgrade/newdirectory-0.0.1/12_secteurs.sql +++ b/upgrade/newdirectory-0.0.1/12_secteurs.sql @@ -84,4 +84,7 @@ ALTER TABLE profile_job_sector_enum DROP COLUMN sect; ALTER TABLE profile_job_subsector_enum DROP COLUMN sect; ALTER TABLE profile_job_subsector_enum DROP COLUMN subsector; + +ALTER TABLE profile_phones CHANGE COLUMN link_type link_type ENUM('address','pro','user', 'hq') NOT NULL DEFAULT 'user'; + -- vim:set syntax=mysql: -- 2.1.4