Exemple #1
0
 public function __construct(array $data)
 {
     foreach ($data as $key => $val) {
         $this->{$key} = $val;
     }
     $this->partner = PartnerSharing::fetchById($this->partner_id);
     $this->sharing_visibility = Visibility::get($this->sharing_level);
 }
Exemple #2
0
 private function fetchJobs(ProfilePage $page)
 {
     // Build the jobs tree
     $jobs = XDB::fetchAllAssoc('SELECT  j.id, j.jobid, je.name,
                                          j.description, j.email AS w_email,
                                          j.email_pub AS w_email_pub,
                                          j.url AS w_url, j.pub, j.entry_year AS w_entry_year
                                    FROM  profile_job      AS j
                               LEFT JOIN  profile_job_enum AS je ON (j.jobid = je.id)
                                   WHERE  j.pid = {?}
                                ORDER BY  j.id', $page->pid());
     if (empty($jobs)) {
         return array($this->emptyJob());
     }
     $compagnies = array();
     $backtrack = array();
     foreach ($jobs as $key => $job) {
         $compagnies[] = $job['jobid'];
         $backtrack[$job['id']] = $key;
     }
     $it = Address::iterate(array($page->pid()), array(Address::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN));
     while ($address = $it->next()) {
         $jobs[$address->id]['w_address'] = $address->toFormArray();
     }
     $it = Phone::iterate(array($page->pid()), array(Phone::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN));
     while ($phone = $it->next()) {
         $jobs[$phone->link_id]['w_phone'][$phone->id] = $phone->toFormArray();
     }
     $res = XDB::iterator("SELECT  e.jtid, e.full_name, j.jid\n                                FROM  profile_job_term_enum AS e\n                          INNER JOIN  profile_job_term AS j USING(jtid)\n                               WHERE  pid = {?}\n                            ORDER BY  j.jid", $page->pid());
     while ($term = $res->next()) {
         // $jid is the ID of the job among this user's jobs
         $jid = $term['jid'];
         if (!isset($backtrack[$jid])) {
             continue;
         }
         $job =& $jobs[$backtrack[$jid]];
         if (!isset($job['terms'])) {
             $job['terms'] = array();
         }
         $job['terms'][] = $term;
     }
     $phone = new Phone();
     $address = new Address();
     foreach ($jobs as $id => &$job) {
         if (!isset($job['w_phone'])) {
             $job['w_phone'] = array(0 => $phone->toFormArray());
         }
         if (!isset($job['w_address'])) {
             $job['w_address'] = $address->toFormArray();
         }
         $job['w_email_new'] = '';
         if (!isset($job['w_email_pub'])) {
             $job['w_email_pub'] = 'private';
         }
     }
     return $jobs;
 }
Exemple #3
0
 public function value(ProfilePage $page, $field, $value, &$success)
 {
     $success = true;
     $addresses = array();
     if (is_null($value)) {
         $it = Address::iterate(array($page->pid()), array(Address::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_ADMIN));
         while ($address = $it->next()) {
             $addresses[] = $address->toFormArray();
         }
         if (count($addresses) == 0) {
             $address = new Address(array('mail' => 1));
             $addresses[] = $address->toFormArray();
         }
         return $addresses;
     }
     return Address::formatFormArray($value, $success);
 }
Exemple #4
0
 /** Tries to return the correct profile from a given hrpid.
  */
 private function findProfile($hrpid = null)
 {
     if (is_null($hrpid)) {
         $user = S::user();
         if (!$user->hasProfile()) {
             return PL_NOT_FOUND;
         } else {
             $profile = $user->profile(false, 0, Visibility::get(Visibility::VIEW_ADMIN));
         }
     } else {
         $profile = Profile::get($hrpid, 0, Visibility::get(Visibility::VIEW_ADMIN));
     }
     if (!$profile) {
         return PL_NOT_FOUND;
     } else {
         if (!S::user()->canEdit($profile) && Platal::notAllowed()) {
             return PL_FORBIDDEN;
         }
     }
     return $profile;
 }
Exemple #5
0
 public function get()
 {
     $cond = $this->getCond();
     $cond->addChild(new UFC_PartnerSharing($this->partner->id));
     $pf = new ProfileFilter($cond, $this->getOrders());
     $pf->restrictVisibilityForPartner($this->partner->id);
     $response = array();
     $matches = $pf->getTotalProfileCount();
     $response['matches'] = $matches;
     $profiles = array();
     if ($matches) {
         // TODO : improve fetching by passing an adequate FETCH field
         $iter = $pf->iterProfiles(new PlLimit($this->amount), 0x0, Visibility::get(Visibility::VIEW_PRIVATE));
         while ($profile = $iter->next()) {
             if ($profile->getPartnerSettings($this->partner->id)->exposed_uid !== 0) {
                 $profile_data = new WSRequestEntry($this->partner, $profile);
                 $profiles[] = $profile_data->getFields($this->fields);
             }
         }
     }
     $response['profiles'] = $profiles;
     return $response;
 }
Exemple #6
0
        printf("\r%u / %u", $i, $total);
    }
}
printf("\r%u / %u", $i, $total);
print "\nFormating done.\n\n";
print "Deletes duplicated phones. (4/4)\n";
$pids = XDB::rawFetchColumn("SELECT  DISTINCT(pid)\n                               FROM  profile_phones AS p1\n                              WHERE  link_type = 'user' AND EXISTS (SELECT  *\n                                                                      FROM  profile_phones AS p2\n                                                                     WHERE  p2.link_type = 'user' AND p2.pid = p1.pid AND p2.tel_id != p1.tel_id)\n                           ORDER BY  pid");
$total = count($pids);
$done = 0;
$aux = 0;
$deleted = 0;
$phones = array();
$duplicates = array();
foreach ($pids as $pid) {
    $count = 0;
    $it = Phone::iterate(array($pid), array(Phone::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_PRIVATE));
    while ($item = $it->next()) {
        $phones[] = $item;
        ++$count;
    }
    for ($i = 0; $i < $count; ++$i) {
        for ($j = $i + 1; $j < $count; ++$j) {
            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)) {
 public function getCode()
 {
     return $this->code[$this->context][Visibility::get($this->visibility)];
 }
Exemple #8
0
 /** Retrieve the 'general' edit visibility.
  * This is the maximum level of fields that may be edited by the current user on other profiles.
  *
  * Rules are:
  *  - Only admins can edit the 'hidden' fields
  *  - If someone has 'directory_edit' (which is actually directory_ax_edit): AX level
  *  - Otherwise, nothing.
  */
 public function editVisibility()
 {
     $level = Visibility::VIEW_NONE;
     if ($this->is_admin) {
         $level = Visibility::VIEW_ADMIN;
     } elseif ($this->checkPerms('directory_edit')) {
         $level = Visibility::VIEW_AX;
     }
     return Visibility::get($level);
 }
Exemple #9
0
 *                                                                         *
 *  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                *
 ***************************************************************************/
/**
 * Check that for every profile, the best postal address which is used to
 * send mail is the right one according to a rule in Address::updateAxMail().
 *
 * To fix something which has been reported by this script, you only need to
 * run "Address::updateBestMail($pid)" with $pid being the Profile ID
 */
require '../connect.db.inc.php';
require_once '../../classes/address.php';
$admin_visibility = Visibility::get(Visibility::VIEW_ADMIN);
// Enumerate every profile
$pids = XDB::iterRow("SELECT pid from profiles");
while ($row = $pids->next()) {
    $pid = $row[0];
    // Find the address which would be selected as "AX mail"
    // But don't update anything
    $best_mail = Address::updateBestMail($pid, true);
    if (is_null($best_mail)) {
        continue;
    }
    // Just continue if the returned address is already selected
    $flags = new PlFlagSet($best_mail['flags']);
    if ($flags->hasFlag('dn_best_mail')) {
        continue;
    }
Exemple #10
0
 public function value(ProfilePage $page, $field, $value, &$success)
 {
     $success = true;
     $phones = array();
     if (is_null($value)) {
         $it = Phone::iterate(array($page->pid()), array(Phone::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_ADMIN));
         while ($phone = $it->next()) {
             $success = $phone->format() && $success;
             $phones[] = $phone->toFormArray();
         }
         if (count($phones) == 0) {
             $phone = new Phone();
             $phones[] = $phone->toFormArray();
         }
         return $phones;
     } else {
         $phones = Phone::formatFormArray($value, $success);
         if (!$success) {
             Platal::page()->trigError('Numéro de téléphone invalide');
         }
         return $phones;
     }
 }
Exemple #11
0
print "Formats addresses.\n";
if ($range != 'a') {
    $where = $targets[$target] . $ranges[$range];
} else {
    $where = null;
}
if ($geocoding_required) {
    // Waiting time is computed as follows: 3600 * 24 / LIMIT,
    // where LIMIT is google's limit reduced to take into account site geocoding.
    $wait = ceil(3600 * 24 / 2000);
    $display_limit = 1;
} else {
    $wait = 0;
    $display_limit = 100;
}
$it = Address::iterate(array(), array(), array(), Visibility::get(Visibility::VIEW_PRIVATE), $where);
$total = $it->total();
$i = 0;
$j = 0;
$skipped = 0;
printf("\r%u / %u", $i, $total);
while ($address = $it->next()) {
    $address->changed = $geocoding_required ? 1 : 0;
    $address->format();
    if ($address->delete()) {
        $address->save(false);
    } else {
        ++$skipped;
    }
    ++$i;
    if ($i == $display_limit) {