123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- //Déclaration d'un item de menu dans le menu principal
- function notification_menu(){
- global $myUser;
- if(!$myUser->can('notification','read')) return;
- ?>
- <div class="dropdown notification_menu ml-auto">
- <button class="btn btn-dark dropdown-toggle" type="button" id="dropdownNotification" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <span class="badge badge-pill badge-danger notification-number hidden">-</span>
- <i class="fas fa-bell"></i>
- </button>
- <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownNotification"></div>
- </div>
- <div class="notification-template">
- <div data-id="{{id}}" class="dropdown-item notification-{{class}} notification-item" onclick="if($(this).hasClass('notification-unread'))notification_user_notification_toggle_read(this,event,'.dropdown-item'); window.location='{{link}}';">
- <ul class="notification-item-options">
- <li onclick="notification_user_notification_toggle_read(this,event,'.dropdown-item')" title="Marquer comme lu" class="notification-read"><i class="fas fa-eye"></i></li>
- <li onclick="notification_user_notification_delete(this,event,'.dropdown-item')" title="Supprimer la notification" class="notification-delete btn-delete"><i class="fas fa-times"></i></li>
- </ul>
- <small>{{created-relative}}</small>
- <strong class="mt-2">{{label}}</strong>
- <p>{{{html}}}</p>
- </div>
- <div class="dropdown-divider" data-notification="{{id}}"></div>
- </div>
- <?php
- }
- //Cette fonction va generer une page quand on clique sur notification dans menu
- function notification_page(){
- global $_;
- if(!isset($_['module']) || $_['module'] !='notification') return;
- $page = !isset($_['page']) ? 'list' : $_['page'];
- $file = __DIR__.SLASH.'page.'.$page.'.php';
- if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
- require_once($file);
- }
- //Fonction executée lors de l'activation du plugin
- function notification_install($id){
- if($id != 'fr.core.notification') return;
- Entity::install(__DIR__);
- require_once(__DIR__.SLASH.'UserNotification.class.php');
- require_once(__DIR__.SLASH.'Notification.class.php');
- $recipients = array();
- foreach (User::getAll(array('right'=>false)) as $user) {
- $recipients[] = $user->login;
- }
- // envoi premiere notif
- Notification::emit(
- array(
- 'label' => "Nouvelle fonctionnalité de notification !",
- 'html' => "Une nouvelle <strong>Notification</strong>
- à été ajoutée à votre espace.<br/> Vous pouvez consulter toutes vos notifications <a href='".ROOT_URL."/index.php?module=notification'>ici</a> et configurer vos <a href='".ROOT_URL."/account.php?section=notification'>préférences la.</a>",
- 'meta' => array(
- 'link' => ROOT_URL.'/index.php?module=notification',
- ),
- 'recipients' => $recipients
- )
- );
- }
- //Fonction executée lors de la désactivation du plugin
- function notification_uninstall($id){
- if($id != 'fr.core.notification') return;
- Entity::uninstall(__DIR__);
- }
- //Déclaration des sections de droits du plugin
- //Déclaration des sections de droits du plugin
- Right::register('notification',array('label'=>'Gestion des droits sur le plugin notification'));
- //Comprends toutes les actions du plugin qui ne nécessitent pas de vue html
- require_once(__DIR__.SLASH.'action.php');
- //Déclaration du menu de réglages
- function notification_menu_setting(&$settingMenu){
- global $myUser;
- if(!$myUser->can('notification','configure')) return;
- $settingMenu[]= array(
- 'sort' =>1,
- 'url' => 'setting.php?section=notification',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Notifications'
- );
- }
- function notification_menu_account(&$accountMenu){
- global $myUser;
- if(!$myUser->connected() || !$myUser->can('notification', 'read')) return;
- $accountMenu[]= array(
- 'sort' => 1,
- 'url' => 'account.php?section=notification',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Notifications',
- );
- }
- //Déclaration des pages de réglages
- function notification_content_setting(){
- global $_;
- if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
- require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
- }
- //Déclaration des pages de réglages
- function notification_content_account(){
- global $_;
- if(file_exists(__DIR__.SLASH.'account.'.$_['section'].'.php'))
- require_once(__DIR__.SLASH.'account.'.$_['section'].'.php');
- }
- //Émission d'une notification
- function notification_emit_notification($params){
- require_once(__DIR__.SLASH.'Notification.class.php');
- Notification::emit($params);
- }
- function notification_methods(&$sendTypes){
- require_once(__DIR__.SLASH.'Notification.class.php');
- require_once(__DIR__.SLASH.'UserNotification.class.php');
- $sendTypes[] = array(
- 'slug' => 'mail',
- 'label' => 'Mail',
- 'explain' => 'Envoi par e-mail',
- 'icon' => 'far fa-envelope-open',
- 'callback' => function($recipient, $infos, $notification){
- if($infos['pinned'] == 1) return;
- if(!isset($recipient)) throw new Exception("Aucun destinataire n'a été renseigné pour l'envoi de mail");
- // ENVOI MAIL
- global $conf;
- $expeditor = $conf->get('notification_mail_from') != '' ? $conf->get('notification_mail_from'): 'Erp <no-reply@core.fr>';
- $reply = $conf->get('notification_mail_reply') != '' ? $conf->get('notification_mail_reply'): 'no-reply@core.fr';
- $mail = new Mail();
- $mail->expeditor = $expeditor;
- $mail->reply = $reply;
- $mail->title = $infos['label'];
- $mail->message = '<h3>'.$infos['label'].'</h3><p>'.$infos['html'].'</p>';
- $mail->message .= (isset($infos['meta']['link'])) ? '<a href="'.$infos['meta']['link'].'">Accéder à l\'outil</a>' : '';
- $usermail = User::byLogin($recipient);
- $mail->recipients['to'][] = $usermail->mail;
- $mail->send();
- }
- );
- $sendTypes[] = array(
- 'slug' => 'interface',
- 'label' => 'Interface',
- 'explain' => 'Visualisation via l\'ERP',
- 'icon' => 'far fa-bell',
- 'callback' => function($recipient, $infos, $notification){
- if($infos['pinned'] == 1) return;
- if(!isset($recipient))
- throw new Exception("Aucun destinataires n\'a été renseignés pour l\'envoi de notifications à travers l\'ERP");
- $userNotification = new UserNotification();
- $userNotification->notification = $notification->id;
- $userNotification->user = $recipient;
- $userNotification->read = 0;
- $userNotification->save();
- }
- );
- }
- function notification_cron($time){
- global $_;
- if(date('H:i', $time)!= '03:00' && !isset($_['force-notification'])) return;
- Plugin::need('notification/Notification');
- Notification::clear();
- }
- Plugin::addHook('widget',function(&$models){
-
- $model = new DashboardWidget();
- $model->icon = 'fas fa-bell';
- $model->headerBackground = '#ffbe5c';
- $model->description = 'Affiche un menu sélectionné';
- $model->label = 'Notification';
- $model->width = 3;
- $model->height = 3;
- $model->model = 'notification';
- $model->css = array(__DIR__.'/css/widget.css?v='.time());
- $model->js = array(__DIR__.'/js/widget.js?v='.time());
-
-
- $model->content = function(&$widget){
- global $myUser;
- User::check_access('notification','read');
- Plugin::need('dashboard/DashboardWidget');
- $widget->title = 'Dernières alertes';
-
-
- if(empty($widget->meta['label'])) $widget->meta['label'] = 'Bloc Menu';
- if(empty($widget->meta['url'])) $widget->meta['url'] = '';
- if(empty($widget->meta['color'])) $widget->meta['color'] = '#007bff';
- ob_start();
- require_once(__DIR__.SLASH.'Notification.class.php');
- require_once(__DIR__.SLASH.'UserNotification.class.php');
- $types = isset($widget->meta['types'])? explode(',',$widget->meta['types']) :array('announcement');
- $max = isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
- $maxlength = isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
-
- $userNotifications = UserNotification::byUser($myUser,array(
- 'limit' => $max,
- 'unread' => false,
- 'types' => $types,
- ));
- ?>
- <div class="notification-container w-100">
- <h5 class="text-uppercase text-center"><i class="far fa-bell"></i> Alertes</h5>
- <ul class="notification-widget-list">
- <?php foreach($userNotifications as $infos):
- $infos['created-relative'] = isset($_['synthesis']) ? relative_time($infos['created'], null, 7) : relative_time($infos['created'], null, 7, true);
- $meta = json_decode($infos['meta']);
- $infos['link'] = 'index.php?module=notification#'.$infos['id'];
- $type = Notification::types($infos['type']);
- ?>
- <li>
- <h5 onclick="document.location.href='<?php echo $infos['link']; ?>';" class="pointer mb-0 mt-1" style="color: <?php echo $type['color']; ?>;">
- <div><i title="<?php echo $type['label'] ?>" class="<?php echo $type['icon'] ?>"></i> <?php echo $infos['label']; ?></div>
- <small class="text-muted d-block"><i class="far fa-clock"></i> <?php echo $infos['created-relative']; ?></small>
- </h5>
- <p class=""><?php echo truncate($infos['html'],$maxlength,array('html'=>true)); ?></p>
- <a class="btn btn-link d-block w-100 text-center" href="<?php echo $infos['link']; ?>">+ d'informations</a>
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php
- $widget->content = ob_get_clean();
- };
- $model->configure = function($widget){
- global $myUser;
- User::check_access('notification','read');
- require_once(__DIR__.SLASH.'Notification.class.php');
- ob_start();
-
- $selectedTypes = isset($widget->meta['types'])? explode(',',$widget->meta['types']) :array('announcement');
- $max = isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
- $maxlength = isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
- ?>
- <div id="navigation-widget-form">
- <div id="notification-widget-form">
- <div class="row">
- <div class="col-md-6 col-sm-12">
- <label for="notification-number">Nb de notifications affichées :</label>
- <input type="number" class="form-control mb-2" value="<?php echo $max; ?>" id="notification-number">
- </div>
- <div class="col-md-6 col-sm-12">
- <label for="notification-length">Nb de caractères affichés :</label>
- <input type="number" class="form-control mb-2" value="<?php echo $maxlength; ?>" id="notification-length">
- </div>
- <div class="col-md-12 col-sm-12">
- <label for="">Types de notifications à afficher :</label>
- <ul class="list-group" id="widget-notification-list">
- <?php foreach(Notification::types() as $slug=>$type): ?>
- <li class="list-group-item p-0">
- <label class="m-0 pointer p-2"><input type="checkbox" onchange="notification_widget_configure_save()"; <?php echo in_array($slug, $selectedTypes)?'checked="checked"':''; ?> value="<?php echo $slug; ?>" data-type="checkbox"><i class="<?php echo $type['icon']; ?>"></i> <?php echo $type['label']; ?> <small class="text-muted">- <?php echo $type['description']; ?></small></label>
- </li>
- <?php endforeach; ?>
- </ul>
- <input type="hidden" id="types" data-id="types" value="<?php echo implode(',',$selectedTypes);?>">
- </div>
- </div>
- </div>
- </div>
- <?php
- };
- $model->save = function($widget,$form){
- global $myUser,$_;
- User::check_access('notification','read');
- require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
-
- if(!isset($form['types'])) throw new Exception("Au moins un type de notification à afficher est requis");
- if(!isset($form['notification-number'])) $form['notification-number'] = 5;
- if(!isset($form['notification-length'])) $form['notification-length'] = 150;
- $widget->meta['types'] = $form['types'];
- $widget->meta['notification-number'] = $form['notification-number'];
- $widget->meta['notification-length'] = $form['notification-length'];
- $widget->save();
- $widget->save();
- };
- $models[$model->model] = $model;
- });
- //Déclaration des settings de base
- //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
- Configuration::setting('notification',array(
- "E-mail",
- 'notification_mail_from' => array("label"=>"Envoi de la part de","legend"=>"Format: Nom <email>, (eg: MyFirm <no-reply@kiss.fr>)","type"=>"text",'placeholder'=>'eg: MyFirm <no-reply@kiss.fr>'),
- 'notification_mail_reply' => array("label"=>"Réponse au mail","legend"=>"Adresse e-mail unique (eg: me@domain.com)","type"=>"text", 'placeholder'=>"eg: me@domain.com"),
- ));
- //Déclation des assets
- Plugin::addCss("/css/main.css");
- Plugin::addJs("/js/main.js");
- //Mapping hook / fonctions
- Plugin::addHook("install", "notification_install");
- Plugin::addHook("uninstall", "notification_uninstall");
- Plugin::addHook("login_header", "notification_menu");
- Plugin::addHook("page", "notification_page");
- Plugin::addHook("menu_account", "notification_menu_account");
- Plugin::addHook("content_account", "notification_content_account");
- Plugin::addHook("menu_setting", "notification_menu_setting");
- Plugin::addHook("content_setting", "notification_content_setting");
- Plugin::addHook("emit_notification", "notification_emit_notification");
- Plugin::addHook("notification_methods", "notification_methods");
- Plugin::addHook("cron", "notification_cron");
- ?>
|