+ XDB::execute("DELETE FROM profile_education
+ WHERE pid = {?} AND !FIND_IN_SET('primary', flags)",
+ $page->pid());
+ foreach ($value as $eduid=>&$edu) {
+ if ($edu['eduid'] != '') {
+ $fieldId = ($edu['fieldid'] == 0) ? null : $edu['fieldid'];
+ XDB::execute("INSERT INTO profile_education
+ SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
+ fieldid = {?}, grad_year = {?}, program = {?}",
+ $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
+ $fieldId, $edu['grad_year'], $edu['program']);
+ }
+ }
+ }
+
+ public function getText($value) {
+ $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS);
+ $degreesList = DirEnum::getOptions(DirEnum::EDUDEGREES);
+ $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS);
+ $educations = array();
+ foreach ($value as $id => $education) {
+ // XXX: the following condition should be removed once there are no more incomplete educations.
+ if (is_null($education['eduid']) || is_null($education['degreeid'])) {
+ if (is_null($education['eduid']) && is_null($education['degreeid'])) {
+ $educations[$id] = 'formation manquante';
+ } else {
+ $educations[$id] = (is_null($education['eduid']) ? 'université manquante' : $schoolsList[$education['eduid']]) . ', '
+ . (is_null($education['degreeid']) ? 'diplôme manquant' : $degreesList[$education['degreeid']]);
+ }
+ } else {
+ $educations[$id] = $schoolsList[$education['eduid']] . ', ' . $degreesList[$education['degreeid']];
+ }
+
+ $details = array();
+ if ($education['grad_year']) {
+ $details[] = $education['grad_year'];
+ }
+ if ($education['program']) {
+ $details[] = '« ' . $education['program'] . ' »';
+ }
+ if ($education['fieldid']) {
+ $details[] = $fieldsList[$education['fieldid']];
+ }
+ if (count($details)) {
+ $educations[$id] .= ' (' . implode(', ', $details) . ')';
+ }
+ }
+ return implode(', ', $educations);
+ }
+}
+
+class ProfileSettingEmailDirectory implements ProfileSetting
+{
+ public function __construct(){}
+ public function save(ProfilePage $page, $field, $value){}
+
+ public function value(ProfilePage $page, $field, $value, &$success)
+ {
+ $p = Platal::page();
+
+ $success = true;
+ if (!is_null($value)) {
+ $email_stripped = strtolower(trim($value));
+ if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) {
+ $p->assign('email_error', '1');
+ $p->assign('email_directory_error', $email_stripped);
+ $p->trigError('Adresse Email invalide');
+ $success = false;
+ } else {
+ $p->assign('email_error', '0');
+ }
+ }
+ return $value;
+ }
+
+ public function getText($value) {
+ return $value;
+ }
+}
+
+class ProfileSettingNetworking implements ProfileSetting
+{
+ private $email;
+ private $pub;
+ private $web;
+ private $number;
+
+ public function __construct()
+ {
+ $this->email = new ProfileSettingEmail();
+ $this->pub = new ProfileSettingPub();
+ $this->web = new ProfileSettingWeb();
+ $this->number = new ProfileSettingNumber();
+ }
+
+ public function value(ProfilePage $page, $field, $value, &$success)
+ {
+ if (is_null($value)) {
+ $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type
+ FROM profile_networking AS n
+ WHERE n.pid = {?}",
+ $page->pid());
+ }
+ if (!is_array($value)) {
+ $value = array();
+ }
+ $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name
+ FROM profile_networking_enum;');
+ $success = true;
+ foreach($value as $i=>&$network) {
+ if (!trim($network['address'])) {
+ unset($value[$i]);
+ } else {
+ if (!isset($network['pub'])) {
+ $network['pub'] = 'private';
+ }
+ $network['error'] = false;
+ $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
+ $s = true;
+ $network['name'] = $filters[$network['type']]['name'];
+ if ($filters[$network['type']]['filter'] == 'web') {
+ $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
+ } elseif ($filters[$network['type']]['filter'] == 'email') {
+ $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
+ } elseif ($filters[$network['type']]['filter'] == 'number') {
+ $network['address'] = $this->number->value($page, 'address', $network['address'], $s);
+ }
+ if (!$s) {
+ $success = false;
+ $network['error'] = true;
+ }
+ }
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage $page, $field, $value)
+ {
+ XDB::execute("DELETE FROM profile_networking
+ WHERE pid = {?}",
+ $page->pid());
+ if (!count($value)) {
+ return;
+ }
+ $insert = array();
+ foreach ($value as $id=>$network) {
+ XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub)
+ VALUES ({?}, {?}, {?}, {?}, {?})",
+ $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
+ }
+ }
+
+ public function getText($value) {
+ static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privé');
+ $networkings = array();
+ foreach ($value as $network) {
+ $networkings[] = $network['name'] . ' : ' . $network['address'] . ' (affichage ' . $pubs[$network['pub']] . ')';
+ }
+ return implode(', ' , $networkings);
+ }
+}
+
+class ProfileSettingPromo implements ProfileSetting
+{
+ public function __construct(){}
+
+ public function save(ProfilePage $page, $field, $value)
+ {
+ $gradYearNew = $value;
+ if ($page->profile->mainEducation() == 'X') {
+ $gradYearNew += $page->profile->mainEducationDuration();
+ }
+ if (($page->profile->mainEducation() != 'X'
+ && $value == $page->profile->entry_year + $page->profile->mainEducationDuration())
+ || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) {
+ XDB::execute('UPDATE profile_display
+ SET promo = {?}
+ WHERE pid = {?}',
+ $page->profile->mainEducation() . strval($value), $page->profile->id());
+ XDB::execute('UPDATE profile_education
+ SET grad_year = {?}
+ WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
+ $gradYearNew, $page->profile->id());
+ Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.');