Example #1
0
 public function save(ProfilePage $page, $field, $value)
 {
     $deletePrivate = S::user()->isMe($page->owner) || S::admin();
     Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, $deletePrivate);
     Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, null, $deletePrivate);
     AddressReq::purge_requests($page->pid(), 0, 0, Address::LINK_PROFILE);
     Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
     if (S::user()->isMe($page->owner) && count($value) > 1) {
         Platal::page()->trigWarning('Attention, tu as plusieurs adresses sur ton profil. Pense à supprimer celles qui sont obsolètes.');
     }
 }
Example #2
0
         if ($phones[$i]->search == $phones[$j]->search) {
             $duplicates[$j] = true;
             if (Visibility::isLessRestrictive($phones[$i]->pub, $phones[$j]->pub)) {
                 $phones[$i]->pub = $phones[$j]->pub;
             }
         }
     }
 }
 if (count($duplicates)) {
     foreach ($duplicates as $key => $bool) {
         unset($phones[$key]);
     }
 }
 if (count($phones) != $count) {
     $deleted += $count - count($phones);
     Phone::deletePhones($pid, 'user');
     $id = 0;
     foreach ($phones as $phone) {
         $phone->setId($id);
         $phone->save();
         ++$id;
     }
     XDB::execute('UPDATE IGNORE  profile_merge_issues
                             SET  issues = REPLACE(issues, \'phone\', \'\')
                           WHERE  pid = {?}', $pid);
 }
 unset($duplicates);
 unset($phones);
 ++$done;
 ++$aux;
 if ($aux == 10) {
Example #3
0
 function handler_jobs($page, $id = -1)
 {
     $page->changeTpl('admin/jobs.tpl');
     if (Env::has('search')) {
         $res = XDB::query("SELECT  id, name, acronym\n                                 FROM  profile_job_enum\n                                WHERE  name LIKE CONCAT('%', {?}, '%') OR acronym LIKE CONCAT('%', {?}, '%')", Env::t('job'), Env::t('job'));
         if ($res->numRows() <= 20) {
             $page->assign('jobs', $res->fetchAllAssoc());
         } else {
             $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !");
         }
         $page->assign('askedJob', Env::v('job'));
         return;
     }
     if (Env::has('edit')) {
         S::assert_xsrf_token();
         $selectedJob = Env::has('selectedJob');
         Phone::deletePhones(0, Phone::LINK_COMPANY, $id);
         Address::deleteAddresses(null, Address::LINK_COMPANY, $id);
         if (Env::has('change')) {
             if (Env::has('newJobId') && Env::i('newJobId') > 0) {
                 XDB::execute('UPDATE  profile_job
                                  SET  jobid = {?}
                                WHERE  jobid = {?}', Env::i('newJobId'), $id);
                 XDB::execute('DELETE FROM  profile_job_enum
                                     WHERE  id = {?}', $id);
                 $page->trigSuccess("L'entreprise a bien été remplacée.");
             } else {
                 $page->trigError("L'entreprise n'a pas été remplacée car l'identifiant fourni n'est pas valide.");
             }
         } else {
             XDB::execute('UPDATE  profile_job_enum
                              SET  name = {?}, acronym = {?}, url = {?}, email = {?},
                                   SIREN_code = {?}, NAF_code = {?}, AX_code = {?}, holdingid = {?}
                            WHERE  id = {?}', Env::t('name'), Env::t('acronym'), Env::t('url'), Env::t('email'), Env::t('SIREN') == 0 ? null : Env::t('SIREN'), Env::t('NAF_code') == 0 ? null : Env::t('NAF_code'), Env::i('AX_code') == 0 ? null : Env::t('AX_code'), Env::i('holdingId') == 0 ? null : Env::t('holdingId'), $id);
             $phone = new Phone(array('display' => Env::v('tel'), 'link_id' => $id, 'id' => 0, 'type' => 'fixed', 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public'));
             $fax = new Phone(array('display' => Env::v('fax'), 'link_id' => $id, 'id' => 1, 'type' => 'fax', 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public'));
             $address = new Address(array('jobid' => $id, 'type' => Address::LINK_COMPANY, 'text' => Env::t('address')));
             $phone->save();
             $fax->save();
             $address->save();
             $page->trigSuccess("L'entreprise a bien été mise à jour.");
         }
     }
     if (!Env::has('change') && $id != -1) {
         $res = XDB::query("SELECT  e.id, e.name, e.acronym, e.url, e.email, e.SIREN_code AS SIREN, e.NAF_code, e.AX_code,\n                                       h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym,\n                                       t.display_tel AS tel, f.display_tel AS fax, a.text AS address\n                                 FROM  profile_job_enum  AS e\n                            LEFT JOIN  profile_job_enum  AS h ON (e.holdingid = h.id)\n                            LEFT JOIN  profile_phones    AS t ON (t.pid = e.id AND t.link_type = 'hq' AND t.tel_id = 0)\n                            LEFT JOIN  profile_phones    AS f ON (f.pid = e.id AND f.link_type = 'hq' AND f.tel_id = 1)\n                            LEFT JOIN  profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq')\n                                WHERE  e.id = {?}", $id);
         if ($res->numRows() == 0) {
             $page->trigError('Auncune entreprise ne correspond à cet identifiant.');
         } else {
             $page->assign('selectedJob', $res->fetchOneAssoc());
         }
     }
 }
Example #4
0
 public static function deleteAddresses($pid, $type, $jobid = null, $groupid = null, $deletePrivate = true)
 {
     $where = '';
     if (!is_null($pid)) {
         $where .= XDB::format(' AND pid = {?}', $pid);
     }
     if (!is_null($jobid)) {
         $where .= XDB::format(' AND jobid = {?}', $jobid);
     }
     if (!is_null($groupid)) {
         $where .= XDB::format(' AND groupid = {?}', $groupid);
     }
     // Prevent buggy callers from accidentally dropping profile_addresses
     if (!$where) {
         throw new Exception("Unable to delete all addresses of the given type, the request was too generic");
     }
     $where_pub = $where . ($deletePrivate ? '' : ' AND pub IN (\'public\', \'ax\')');
     if ($deletePrivate) {
         XDB::execute('DELETE FROM  profile_addresses_components
                             WHERE  type = {?}' . $where, $type);
     } else {
         // Delete address components one by one if $deletePrivate is not requested
         $res = XDB::iterator('SELECT  pid, jobid, groupid, type, id
                                 FROM  profile_addresses
                                WHERE  type = {?}' . $where_pub, $type);
         while ($values = $res->next()) {
             XDB::execute('DELETE FROM  profile_addresses_components
                                 WHERE  pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', $values['pid'], $values['jobid'], $values['groupid'], $values['type'], $values['id']);
         }
     }
     XDB::execute('DELETE FROM  profile_addresses
                         WHERE  type = {?}' . $where_pub, $type);
     if ($type == self::LINK_PROFILE) {
         Phone::deletePhones($pid, Phone::LINK_ADDRESS, null, $deletePrivate);
     }
 }
Example #5
0
 public function save(ProfilePage $page, $field, $value)
 {
     $deletePrivate = S::user()->isMe($page->owner) || S::admin();
     XDB::execute('DELETE FROM  pj, pjt
                         USING  profile_job      AS pj
                     LEFT JOIN  profile_job_term AS pjt ON (pj.pid = pjt.pid AND pj.id = pjt.jid)
                         WHERE  pj.pid = {?}' . ($deletePrivate ? '' : ' AND pj.pub IN (\'public\', \'ax\')'), $page->pid());
     Address::deleteAddresses($page->pid(), Address::LINK_JOB, null, null, $deletePrivate);
     Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
     $previous_requests = EntrReq::get_typed_requests($page->pid(), 'entreprise');
     foreach ($previous_requests as $request) {
         $request->clean();
     }
     $terms_values = array();
     foreach ($value as $id => &$job) {
         if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) {
             if (isset($job['jobid']) && $job['jobid']) {
                 XDB::execute('INSERT INTO  profile_job (pid, id, description, email, entry_year,
                                                         url, pub, email_pub, jobid)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
             } else {
                 XDB::execute('INSERT INTO  profile_job (pid, id, description, email, entry_year,
                                                         url, pub, email_pub)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub']);
                 $request = new EntrReq(S::user(), $page->profile, $id, $job['name'], $job['hq_acronym'], $job['hq_url'], $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
                 $request->submit();
                 sleep(1);
             }
             $address = new Address(array_merge($job['w_address'], array('pid' => $page->pid(), 'id' => $id, 'type' => Address::LINK_JOB)));
             $address->save();
             Phone::savePhones($job['w_phone'], $page->pid(), Phone::LINK_JOB, $id);
             if (isset($job['terms'])) {
                 foreach ($job['terms'] as $term) {
                     $terms_values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $id, $term['jtid'], "original");
                 }
             }
         }
     }
     if (count($terms_values) > 0) {
         XDB::rawExecute('INSERT INTO  profile_job_term (pid, jid, jtid, computed)
                               VALUES  ' . implode(', ', $terms_values) . '
              ON DUPLICATE KEY UPDATE  computed = VALUES(computed)');
     }
     if (S::user()->isMe($page->owner) && count($value) > 1) {
         Platal::page()->trigWarning('Attention, tu as plusieurs emplois sur ton profil. Pense à supprimer ceux qui sont obsolètes.');
     }
 }
Example #6
0
 public function save(ProfilePage $page, $field, $value)
 {
     Phone::deletePhones($page->pid(), Phone::LINK_PROFILE, null, S::user()->isMe($page->owner) || S::admin());
     Phone::savePhones($value, $page->pid(), Phone::LINK_PROFILE);
 }
Example #7
0
 function handler_edit($page)
 {
     global $globals;
     $page->changeTpl('xnetgrp/edit.tpl');
     $error = false;
     if (S::admin()) {
         $domains = XDB::iterator('SELECT  *
                                     FROM  group_dom
                                 ORDER BY  nom');
         $page->assign('domains', $domains);
         $page->assign('super', true);
     }
     if (Post::has('submit')) {
         S::assert_xsrf_token();
         $flags = new PlFlagSet('wiki_desc');
         $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1);
         $site = Post::t('site');
         if ($site && $site != "http://") {
             $scheme = parse_url($site, PHP_URL_SCHEME);
             if (!$scheme) {
                 $site = "http://" . $site;
             }
         } else {
             $site = "";
         }
         $notify_all = Post::v('notify_all') ? true : false;
         if (!$notify_all) {
             $to_notify = array();
             $uf = new UserFilter(new UFC_Group($globals->asso('id'), true));
             $uids = $uf->getIds();
             foreach ($uids as $uid) {
                 if (Post::b('to_notify_' . $uid)) {
                     $to_notify[] = $uid;
                 }
             }
             if (count($to_notify) == 0) {
                 $notify_all = true;
                 $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
             }
         }
         $flags->addFlag('notify_all', $notify_all);
         if (S::admin()) {
             $page->assign('super', true);
             if (Post::v('mail_domain') && strstr(Post::v('mail_domain'), '.') === false) {
                 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée)&nbsp;!!!');
                 $error = true;
             }
             if (Post::t('nom') == '' || Post::t('diminutif') == '') {
                 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
                 $error = true;
             }
             if ($error) {
                 $page->assign('nom', Post::t('nom'));
                 $page->assign('diminutif', Post::t('diminutif'));
                 $page->assign('mail_domain', Post::t('mail_domain'));
                 $page->assign('cat', Post::v('cat'));
                 $page->assign('dom', Post::v('dom'));
                 $page->assign('ax', Post::v('ax'));
                 $page->assign('axDate', Post::t('axDate'));
                 $page->assign('site', $site);
                 $page->assign('resp', Post::t('resp'));
                 $page->assign('mail', Post::t('mail'));
                 $page->assign('phone', Post::t('phone'));
                 $page->assign('fax', Post::t('fax'));
                 $page->assign('address', Post::t('address'));
                 $page->assign('forum', Post::t('forum'));
                 $page->assign('inscriptible', Post::v('inscriptible'));
                 $page->assign('sub_url', Post::t('sub_url'));
                 $page->assign('unsub_url', Post::t('unsub_url'));
                 $page->assign('welcome_msg', Post::t('welcome_msg'));
                 $page->assign('pub', Post::v('pub'));
                 $page->assign('notif_unsub', Post::i('notif_unsub'));
                 $page->assign('descr', Post::t('descr'));
                 $page->assign('disable_mails', Post::b('disable_mails'));
                 $page->assign('status', Post::v('status'));
                 $page->assign('error', $error);
                 return;
             }
             $axDate = make_datetime(Post::v('axDate'));
             if (Post::t('axDate') != '') {
                 $axDate = make_datetime(Post::v('axDate'))->format('Y-m-d');
             } else {
                 $axDate = null;
             }
             XDB::execute("UPDATE  groups\n                        SET  nom={?}, diminutif={?}, cat={?}, dom={?},\n                             descr={?}, site={?}, mail={?}, resp={?},\n                             forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},\n                             sub_url={?}, inscriptible={?}, unsub_url={?},\n                             flags = {?}, welcome_msg = {?}, disable_mails = {?},\n                             status = {?}\n                      WHERE  id={?}", Post::v('nom'), Post::v('diminutif'), Post::v('cat'), Post::i('dom') == 0 ? null : Post::i('dom'), Post::v('descr'), $site, Post::v('mail'), Post::v('resp'), Post::v('forum'), Post::v('mail_domain'), Post::has('ax'), $axDate, Post::v('pub'), Post::v('sub_url'), Post::v('inscriptible'), Post::v('unsub_url'), $flags, Post::t('welcome_msg'), Post::b('disable_mails'), Post::v('status'), $globals->asso('id'));
             if (Post::v('mail_domain')) {
                 XDB::execute('INSERT IGNORE INTO  email_virtual_domains (name)
                                           VALUES  ({?})', Post::t('mail_domain'));
                 XDB::execute('UPDATE  email_virtual_domains
                                  SET  aliasing = id
                                WHERE  name = {?}', Post::t('mail_domain'));
             }
         } else {
             XDB::execute("UPDATE  groups\n                        SET  descr={?}, site={?}, mail={?}, resp={?},\n                             forum={?}, pub= {?}, sub_url={?},\n                             unsub_url = {?}, flags = {?}, welcome_msg = {?},\n                             status = {?}\n                      WHERE  id={?}", Post::v('descr'), $site, Post::v('mail'), Post::v('resp'), Post::v('forum'), Post::v('pub'), Post::v('sub_url'), Post::v('unsub_url'), $flags, Post::t('welcome_msg'), Post::v('status'), $globals->asso('id'));
         }
         Phone::deletePhones(0, Phone::LINK_GROUP, $globals->asso('id'));
         $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0, 'type' => 'fixed', 'display' => Post::v('phone'), 'pub' => 'public'));
         $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1, 'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public'));
         $phone->save();
         $fax->save();
         Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id'));
         $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address')));
         $address->save();
         if ($_FILES['logo']['name']) {
             $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true);
             if (!$upload) {
                 $page->trigError("Impossible de télécharger le logo.");
             } else {
                 XDB::execute('UPDATE  groups
                                  SET  logo = {?}, logo_mime = {?}
                                WHERE  id = {?}', $upload->getContents(), $upload->contentType(), $globals->asso('id'));
                 $upload->rm();
             }
         }
         XDB::execute("UPDATE  group_members\n                             SET  flags = ''\n                           WHERE  asso_id = {?}", $globals->asso('id'));
         if (!$notify_all) {
             XDB::execute("UPDATE  group_members\n                                 SET  flags = 'notify'\n                               WHERE  asso_id = {?} AND uid IN {?}", $globals->asso('id'), $to_notify);
         }
         pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
     }
     $uf = new UserFilter(new UFC_Group($globals->asso('id'), true, UFC_Group::NOTIFIED));
     $page->assign('notified', $uf->getUsers());
     $uf = new UserFilter(new UFC_Group($globals->asso('id'), true, UFC_Group::UNNOTIFIED));
     $page->assign('unnotified', $uf->getUsers());
     $page->assign('error', $error);
     $page->assign('cat', $globals->asso('cat'));
     $page->assign('dom', $globals->asso('dom'));
     $page->assign('ax', $globals->asso('ax'));
     $page->assign('inscriptible', $globals->asso('inscriptible'));
     $page->assign('pub', $globals->asso('pub'));
     $page->assign('notif_unsub', $globals->asso('notif_unsub'));
     $page->assign('notify_all', $globals->asso('notify_all'));
     $page->assign('disable_mails', $globals->asso('disable_mails'));
     $page->assign('status', $globals->asso('status'));
 }