+// }}}
+// {{{ function add_user_address()
+function add_user_address($uid, $adrid, $adr) {
+ XDB::execute(
+ "INSERT INTO adresses (`uid`, `adrid`, `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `datemaj`, `pub`) (
+ SELECT u.user_id, {?}, {?}, {?}, {?}, {?}, {?}, gp.a2, NOW(), {?}
+ FROM auth_user_md5 AS u
+ LEFT JOIN geoloc_pays AS gp ON (gp.pays LIKE {?} OR gp.country LIKE {?} OR gp.a2 LIKE {?})
+ WHERE u.user_id = {?}
+ LIMIT 1)",
+ $adrid, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], $adr['pub'], $adr['countrytxt'], $adr['countrytxt'], $adr['countrytxt'], $uid);
+ if (isset($adr['tels']) && is_array($adr['tels'])) {
+ $telid = 0;
+ foreach ($adr['tels'] as $tel) if ($tel['tel']) {
+ add_user_tel($uid, $adrid, $telid, $tel);
+ $telid ++;
+ }
+ }
+}
+// }}}
+// {{{ function update_user_address()
+function update_user_address($uid, $adrid, $adr) {
+ // update address
+ XDB::execute(
+ "UPDATE adresses AS a LEFT JOIN geoloc_pays AS gp ON (gp.pays = {?})
+ SET `adr1` = {?}, `adr2` = {?}, `adr3` = {?},
+ `postcode` = {?}, `city` = {?}, a.`country` = gp.a2, `datemaj` = NOW(), `pub` = {?}
+ WHERE adrid = {?} AND uid = {?}",
+ $adr['country_txt'],
+ $adr['adr1'], $adr['adr2'], $adr['adr3'],
+ $adr['postcode'], $adr['city'], $adr['pub'], $adrid, $uid);
+ if (isset($adr['tels']) && is_array($adr['tels'])) {
+ $res = XDB::query("SELECT telid FROM tels WHERE uid = {?} AND adrid = {?} ORDER BY telid", $uid, $adrid);
+ $telids = $res->fetchColumn();
+ foreach ($adr['tels'] as $tel) {
+ if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) {
+ remove_user_tel($uid, $adrid, $tel['telid']);
+ if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]);
+ } else if (isset($tel['telid'])) {
+ update_user_tel($uid, $adrid, $tel['telid'], $tel);
+ } else {
+ for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++);
+ add_user_tel($uid, $adrid, $telid, $tel);
+ }
+ }
+ }
+}
+// }}}
+// {{{ function remove_user_address()
+function remove_user_address($uid, $adrid) {
+ XDB::execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
+ XDB::execute("DELETE FROM tels WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
+}
+// }}}
+// {{{ function add_user_tel()
+function add_user_tel($uid, $adrid, $telid, $tel) {
+ XDB::execute(
+ "INSERT INTO tels SET uid = {?}, adrid = {?}, telid = {?}, tel = {?}, tel_type = {?}, tel_pub = {?}",
+ $uid, $adrid, $telid, $tel['tel'], $tel['tel_type'], $tel['tel_pub']);
+}
+// }}}
+// {{{ function update_user_tel()
+function update_user_tel($uid, $adrid, $telid, $tel) {
+ XDB::execute(
+ "UPDATE tels SET tel = {?}, tel_type = {?}, tel_pub = {?}
+ WHERE telid = {?} AND adrid = {?} AND uid = {?}",
+ $tel['tel'], $tel['tel_type'], $tel['tel_pub'],
+ $telid, $adrid, $uid);
+}
+// }}}
+// {{{ function remove_user_tel()
+function remove_user_tel($uid, $adrid, $telid) {
+ XDB::execute("DELETE FROM tels WHERE telid = {?} AND adrid = {?} AND uid = {?}",
+ $telid, $adrid, $uid);
+}
+// }}}
+// {{{ function add_user_pro()
+function add_user_pro($uid, $entrid, $pro) {
+ XDB::execute(
+ "INSERT INTO entreprises (`uid`, `entrid`, `entreprise`, `poste`, `secteur`, `ss_secteur`, `fonction`,
+ `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `region`, `tel`, `fax`, `mobile`, `email`, `web`, `pub`, `adr_pub`, `tel_pub`, `email_pub`)
+ SELECT u.user_id, {?}, {?}, {?}, s.id, ss.id, f.id,
+ {?}, {?}, {?}, {?}, {?}, gp.a2, gr.region, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}
+ FROM auth_user_md5 AS u
+ LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?})
+ LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?})
+ LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})
+ LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?})
+ LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})
+ WHERE u.user_id = {?}
+ LIMIT 1",
+ $entrid, $pro['entreprise'], $pro['poste'],
+ $pro['adr1'], $pro['adr2'], $pro['adr3'], $pro['postcode'], $pro['city'], $pro['tel'], $pro['fax'], $pro['mobile'], $pro['email'], $pro['web'], $pro['pub'], $pro['adr_pub'], $pro['tel_pub'], $pro['email_pub'],
+ $pro['secteur'], $pro['sous_secteur'], $pro['fonction'], $pro['fonction'],
+ $pro['countrytxt'], $pro['countrytxt'], $pro['region'],
+ $uid);
+}
+// }}}
+// {{{ function update_user_pro()
+function update_user_pro($uid, $entrid, $pro) {
+ $join = "";
+ $set = "";
+ $args_join = array();
+ $args_set = array();
+
+ $join .= "LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?})
+ LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?})
+ LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})";
+ $args_join[] = $pro['secteur'];
+ $args_join[] = $pro['sous_secteur'];
+ $args_join[] = $pro['fonction'];
+ $args_join[] = $pro['fonction'];
+ $set .= ", e.`entreprise` = {?}, e.`secteur` = s.id, e.`ss_secteur` = ss.id, e.`fonction` = f.id, e.`poste`= {?}, e.`web` = {?}, e.`pub` = {?}";
+ $args_set[] = $pro['entreprise'];
+ $args_set[] = $pro['poste'];
+ $args_set[] = $pro['web'];
+ $args_set[] = $pro['pub'];
+
+ if (isset($pro['adr1'])) {
+ $join .= "LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?})
+ LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})";
+ $args_join[] = $pro['countrytxt'];
+ $args_join[] = $pro['countrytxt'];
+ $args_join[] = $pro['region'];
+ $set .= ", e.`adr1` = {?}, e.`adr2` = {?}, e.`adr3` = {?}, e.`postcode` = {?}, e.`city` = {?}, e.`country` = gp.a2, e.`region` = gr.region, e.`adr_pub` = {?}";
+ $args_set[] = $pro['adr1'];
+ $args_set[] = $pro['adr2'];
+ $args_set[] = $pro['adr3'];
+ $args_set[] = $pro['postcode'];
+ $args_set[] = $pro['city'];
+ $args_set[] = $pro['adr_pub'];
+ }