Пример #1
0
 /**
  * Get remote IP address, with reverse proxy support
  * @return IP
  */
 public static function getInstance()
 {
     global $globals;
     static $ipObject = null;
     // Cache
     if (!is_null($ipObject)) {
         return $ipObject;
     }
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // Resolve reverse proxy configuration
     if (!empty($globals->core->remoteproxy)) {
         $remote_proxies = unflatten($globals->core->remoteproxy);
         $remote_proxies = array_map('trim', $remote_proxies);
         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
             $ipList = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']);
             $ipList = array_map('trim', $ipList);
             for ($ipTest = $ip; $ipTest; $ipTest = array_pop($ipList)) {
                 if (!in_array($ipTest, $remote_proxies)) {
                     $ip = $ipTest;
                     break;
                 }
             }
         }
     }
     // Set cache and return an IP object
     return $ipObject = new IPAddress($ip);
 }
Пример #2
0
function smarty_modifier_rights($rights, $defaults = null, $hoverable = false)
{
    $rights = unflatten($rights);
    if ($defaults === null) {
        $defaults = $rights;
    }
    $keys = array();
    foreach ($rights as $right) {
        $keys[(string) $right] = true;
    }
    $strings = array();
    foreach ($defaults as $right) {
        $key = (string) $right;
        $label = $key;
        switch ($key) {
            case 'admin':
                $label = 'Administrateur';
                break;
            case 'member':
                $label = 'Membre';
                break;
            case 'friend':
                $label = 'Sympathisant';
                break;
        }
        $has = $keys[$key] ? 'on' : 'off';
        $hoverable = $hoverable ? 'hoverable' : '';
        $strings[] = '<div title="' . $label . '" class="rights ' . $key . ' ' . $has . ' ' . $hoverable . '"></div>';
    }
    return implode('', $strings);
}
Пример #3
0
 public function __construct($cs)
 {
     if ($cs instanceof Collection) {
         $this->cids = $cs->ids();
     } else {
         $this->cids = Caste::toIds(unflatten($cs));
     }
 }
Пример #4
0
 public function __construct($us)
 {
     $this->uids = User::toIds(unflatten($us));
 }
Пример #5
0
 public function __construct($gs)
 {
     if ($gs instanceof Collection) {
         $this->gids = $gs->ids();
     } else {
         $this->gids = Group::toIds(unflatten($gs));
     }
 }
Пример #6
0
 public function __construct($rooms, $exact = false)
 {
     $this->rooms = Room::toIds(unflatten($rooms));
     $this->exact = $exact;
 }
Пример #7
0
 public static function get($names, $run = true)
 {
     global $globals;
     $array_passed = is_array($names);
     $names = unflatten($names);
     $minimodules = array();
     foreach ($names as $name) {
         $m = self::instantiate($name);
         if ($m !== false) {
             $minimodules[$m->name] = $m;
             self::$minimodules[$m->name] = $m;
             if ($m->checkAuthAndPerms() && $run) {
                 try {
                     $m->run();
                 } catch (Exception $e) {
                     $m->error = $e;
                     if ($globals->debug & DEBUG_BT) {
                         if (!isset(PlBacktrace::$bt['Minimodule'])) {
                             new PlBacktrace('Minimodule');
                         }
                         PlBacktrace::$bt['Minimodule']->newEvent($name, 0, $e->getMessage(), array(array('file' => $e->getFile(), 'line' => $e->getLine())));
                     }
                 }
             }
         }
     }
     return $array_passed ? $minimodules : flatten($minimodules);
 }
Пример #8
0
 function handler_ajax_modify($page, $type)
 {
     $json = json_decode(Env::v('json'));
     if ($type == 'instance') {
         $id = $json->admin_id;
         $ai = new ActivityInstance($id);
         $ai->select(ActivityInstanceSelect::base());
         if (!S::user()->hasRights($ai->target()->group(), Rights::admin())) {
             throw new Exception("Invalid credentials");
         }
         S::assert_xsrf_token();
         try {
             $begin = new FrankizDateTime($json->begin);
             $end = new FrankizDateTime($json->end);
             if ($ai->regular()) {
                 $ai->comment($json->activity_comment);
                 $ai->begin($begin);
                 $ai->end($end);
             } else {
                 $ai->begin($begin);
                 $ai->end($end);
                 $a = $ai->activity();
                 $a->title($json->title);
                 $a->description($json->activity_description);
             }
             $page->jsonAssign('success', true);
         } catch (Exception $e) {
             $page->jsonAssign('success', false);
         }
     } else {
         if ($type == 'regular') {
             $id = $json->aid;
             $a = new Activity($id);
             $a->select(ActivitySelect::base());
             if (!S::user()->hasRights($a->target()->group(), Rights::admin())) {
                 throw new Exception("Invalid credentials");
             }
             S::assert_xsrf_token();
             if (preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->begin) && strtotime($json->begin) !== false && preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->end) && strtotime($json->end) !== false) {
                 $a->title($json->title);
                 $a->description($json->activity_description);
                 $key = 'days[]';
                 $days = unflatten($json->{$key});
                 $a->days(implode(',', $days));
                 $a->default_begin($json->begin);
                 $a->default_end($json->end);
                 $page->jsonAssign('success', true);
             } else {
                 $page->jsonAssign('success', false);
             }
         }
     }
     return PL_JSON;
 }
Пример #9
0
 /**
  * Remove items from the Collection
  *
  * @param $cs  An Item, an id or an array containing them
  */
 public function remove($cs)
 {
     $className = $this->className;
     $cs = $cs instanceof Collection ? $cs : unflatten($cs);
     foreach ($cs as $c) {
         if ($c instanceof $className) {
             unset($this->collected[$c->id()]);
         } else {
             unset($this->collected[$c]);
         }
     }
     return $this;
 }
Пример #10
0
 public function __construct($ais)
 {
     $this->aids = ActivityInstance::toIds(unflatten($ais));
 }
Пример #11
0
 public function __construct($us, $rights)
 {
     $this->uids = User::toIds(unflatten($us));
     $this->rights = (string) empty($rights) ? Rights::member() : $rights;
 }
Пример #12
0
 public function addCssLink($css)
 {
     $csss = unflatten($css);
     $exceptions = array();
     foreach ($csss as $css) {
         try {
             parent::addCssLink(self::getCssPath($css));
         } catch (SkinFileNotFoundException $e) {
             $exceptions[] = $e;
         }
     }
     return SkinFileNotFoundException::merge($exceptions);
 }
Пример #13
0
 public static function toId($object)
 {
     return flatten(static::toIds(unflatten($object)));
 }
Пример #14
0
 function handler_mail($page)
 {
     $subject = Env::t('subject', '');
     $body = Env::t('mail_body', '');
     $no_wiki = Env::has('no_wiki');
     // Retrieve the years on_platal of each formation
     $formations = Formation::selectAll(FormationSelect::on_platal());
     if (Env::has('send')) {
         try {
             $required_fields = array('subject' => 'Il faut donner un sujet à ton mail', 'mail_body' => 'Tu ne veux pas envoyer de mail vide à tous. Si ?');
             foreach ($required_fields as $field => $msg) {
                 if (Env::v($field, '') == '') {
                     throw new Exception($msg);
                 }
             }
             if (Env::t('origin_mail_proposal') == 'false') {
                 $origin = false;
             } else {
                 $origin = new Group(Env::i('origin_mail_proposal'));
             }
             if ($origin !== false && !S::user()->hasRights($origin, Rights::admin())) {
                 throw new Exception("Invalid credentials for origin Group");
             }
             if (Env::t('type_mail_proposal') == 'group') {
                 // Mail to a group
                 list($temp, $target_group) = self::target_picker_to_caste_group('mail');
                 $target = new Collection('Caste');
                 $target->add($temp);
                 $target_group->select(GroupSelect::validate());
                 $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group));
                 $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail'));
                 $el->insert();
             } elseif (Env::t('type_mail_proposal') == 'promo') {
                 // Target group is a Collection of formation groups, which validate requests
                 $target_group = new Collection('Group');
                 // Group promos by formation
                 $promos = unflatten(Env::v('promos'));
                 $promosByFormation = array();
                 foreach ($promos as $formation_promo) {
                     $formation_promo = trim($formation_promo);
                     if (!$formation_promo) {
                         continue;
                     }
                     if (!preg_match('/^([0-9]+)_([0-9]+)$/', $formation_promo, $matches)) {
                         throw new Exception("Oops, mauvais format de destinataire.");
                     }
                     $formid = (int) $matches[1];
                     $promo = (int) $matches[2];
                     if (isset($promosByFormation[$formid])) {
                         $promosByFormation[$formid][] = $promo;
                     } else {
                         $promosByFormation[$formid] = array($promo);
                     }
                 }
                 if (empty($promosByFormation)) {
                     throw new Exception("Il faut indiquer au moins un destinataire.");
                 }
                 foreach ($promosByFormation as $formid => $promos) {
                     // Now, $promos are the list of promos of formation $formid
                     $form = $formations->get($formid);
                     // Study group are the people the mail is sent to, array of CasteFilterCondition
                     $cfc_study_groups = array();
                     foreach ($promos as $promo) {
                         if (!$form->hasPlatalYear($promo)) {
                             throw new Exception("Mauvaise promo " . $promo . " pour " . $form->label() . ".");
                         }
                         $cfc_study_groups[] = new CFC_Group($form->getGroupForPromo($promo), Rights::restricted());
                     }
                     $target = new CasteFilter(new PFC_Or($cfc_study_groups));
                     $target = $target->get();
                     $target->select(CasteSelect::validate());
                     // $target_group is the group which validates this email
                     $target_group = $form->getGroup();
                     $target_group->select(GroupSelect::validate());
                     $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group));
                     $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail'));
                     $el->insert();
                 }
             }
             $page->assign('envoye', true);
         } catch (Exception $e) {
             $page->trigError($e->getMessage());
         }
     }
     $page->assign('subject', $subject);
     $page->assign('body', $body);
     $page->assign('nowiki', $no_wiki);
     $page->assign('formations', $formations);
     $page->assign('title', 'Envoi des mails');
     $page->addCssLink('validate.css');
     $page->changeTpl('validate/prop.mail.tpl');
 }
Пример #15
0
 public function delete_participants($p)
 {
     $users = unflatten($p);
     $values = array();
     foreach ($users as $user) {
         if ($user instanceof User) {
             $values[] = '(' . $this->id . ',' . $user->id() . ')';
         } else {
             if (self::isId($user)) {
                 $values[] = '(' . $this->id . ',' . $user . ')';
             }
         }
     }
     if (!empty($values)) {
         $values = '(' . implode(',', $values) . ')';
         XDB::execute('DELETE FROM  activities_participants
                             WHERE  (id,participant) IN ' . $values);
     }
 }