|
|
@@ -22,13 +22,165 @@ class Route_Notify extends RouteBase {
|
|
|
|
|
|
public function defaultAction() {
|
|
|
SE_Layout::gora();
|
|
|
+ try {
|
|
|
+ $this->formUserTableReminder();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
|
|
|
+ }
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rmAction() {
|
|
|
+ SE_Layout::gora();
|
|
|
+ try {
|
|
|
+ $this->rmUserTableReminder($_GET);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
|
|
|
+ }
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rmUserTableReminder($args) {
|
|
|
+ throw new Exception("TODO: rm args:" . json_encode($args));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function formUserTableReminder() {
|
|
|
+ $usrLogin = User::getLogin();
|
|
|
+ echo '<div class="container">';
|
|
|
+ $subTask = V::get('_subTask', '', $_POST);
|
|
|
+ if ('_add_table_reminder' == $subTask) {
|
|
|
+ try {
|
|
|
+ $this->addUserTableReminder($usrLogin, $_POST);
|
|
|
+ SE_Layout::alert('info', "Dodano przypomnienie");
|
|
|
+ } catch (Exception $e) {
|
|
|
+ SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $userReminders = $this->getUserReminders($usrLogin);
|
|
|
?>
|
|
|
-<div class="container">
|
|
|
- <h1>Nofitication system</h1>
|
|
|
- ...
|
|
|
-</div>
|
|
|
+ <h1>Powiadomienia dla <code><?php echo $usrLogin; ?></code></h1>
|
|
|
+ <?php if (empty($userReminders)) : ?>
|
|
|
+ <?php SE_Layout::alert('warning', "Brak zdefiniowanych przypomnień"); ?>
|
|
|
+ <?php else : ?>
|
|
|
+ <table class="table table-hovered">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>rodzaj</th>
|
|
|
+ <th>jak często</th>
|
|
|
+ <th>utworzony</th>
|
|
|
+ <th>ostatnio uruchomiony</th>
|
|
|
+ <th></th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <?php foreach ($userReminders as $reminder) : ?>
|
|
|
+ <tr>
|
|
|
+ <td><?php echo $this->printValue('what', $reminder['what']); ?></td>
|
|
|
+ <td><?php echo $this->printValue('when', $reminder['when']); ?></td>
|
|
|
+ <td><?php echo $reminder['_created']; ?></td>
|
|
|
+ <td><?php echo ($reminder['last_exec_time'])? $reminder['last_exec_time'] : '<i>brak danych</i>'; ?></td>
|
|
|
+ <td><a href="index.php?_route=Notify&_task=rm&who=<?php echo $usrLogin; ?>&what=<?php echo $reminder['what']; ?>&when=<?php echo $reminder['when']; ?>"
|
|
|
+ onclick="return confirm('Czy usunąć przypomnienie?')"
|
|
|
+ ><i class="glyphicon glyphicon-remove" style="color:red;opacity:0.4;"></i></a></td>
|
|
|
+ </tr>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <?php endif; ?>
|
|
|
+
|
|
|
+ <hr>
|
|
|
+ <h4>Dodaj powiadomienia dla wybranych tabel:</h4>
|
|
|
+ <form method="post" class="form-inline">
|
|
|
+ <input type="hidden" name="_subTask" value="_add_table_reminder">
|
|
|
+ <label>rodzaj:</label>
|
|
|
+ <select type="select" name="what" class="form-control">
|
|
|
+ <option value="">[ Wybierz ]</option>
|
|
|
+ <option value="l_app_projekty">projekty</option>
|
|
|
+ <option value="l_app_koresp">korespondencja</option>
|
|
|
+ <option value="l_app_zadania">zadania</option>
|
|
|
+ <option value="l_app_procesy">procesy</option>
|
|
|
+ <option value="l_app_zasoby">zasoby</option>
|
|
|
+ <option value="l_app_all_przypomnij">*wszystkie</option>
|
|
|
+ </select>
|
|
|
+ <label>jak często:</label>
|
|
|
+ <select type="select" name="when" class="form-control">
|
|
|
+ <option value="">[ Wybierz ]</option>
|
|
|
+ <option value="once_a_day">Raz dziennie</option>
|
|
|
+ </select>
|
|
|
+ <input type="submit" value="Dodaj" class="btn btn-primary">
|
|
|
+ </form>
|
|
|
<?php
|
|
|
- SE_Layout::dol();
|
|
|
+ echo '</div>';// .container
|
|
|
+ }
|
|
|
+
|
|
|
+ public function printValue($fldName, $argValue) {
|
|
|
+ if ('what' == $fldName || 'when' == $fldName) {
|
|
|
+ $valueLabels = $this->getFieldValueLabels($fldName);
|
|
|
+ return V::get($argValue, $argValue, $valueLabels);
|
|
|
+ }
|
|
|
+ return $argValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFieldValueLabels($fldName) {
|
|
|
+ $valueLabels = array();
|
|
|
+ if ('what' == $fldName) {
|
|
|
+ $valueLabels['l_app_projekty'] = "projekty";
|
|
|
+ $valueLabels['l_app_koresp'] = "korespondencja";
|
|
|
+ $valueLabels['l_app_zadania'] = "zadania";
|
|
|
+ $valueLabels['l_app_procesy'] = "procesy";
|
|
|
+ $valueLabels['l_app_zasoby'] = "zasoby";
|
|
|
+ $valueLabels['l_app_all_przypomnij'] = "*wszystkie";
|
|
|
+ } else if ('when' == $fldName) {
|
|
|
+ $valueLabels['once_a_day'] = "Raz dziennie";
|
|
|
+ }
|
|
|
+ return $valueLabels;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addUserTableReminder($usrLogin, $args) {
|
|
|
+ $what_values = array();
|
|
|
+ $what_values[] = 'l_app_projekty';
|
|
|
+ $what_values[] = 'l_app_koresp';
|
|
|
+ $what_values[] = 'l_app_zadania';
|
|
|
+ $what_values[] = 'l_app_procesy';
|
|
|
+ $what_values[] = 'l_app_zasoby';
|
|
|
+ $what_values[] = 'l_app_all_przypomnij';
|
|
|
+ $what = V::validate('what', $args, array('type'=>'word', 'not_empty'=>true, 'max_length'=>'255', 'values'=>$what_values));
|
|
|
+ $when_values = array();
|
|
|
+ $when_values[] = 'once_a_day';
|
|
|
+ $when = V::validate('when', $args, array('type'=>'word', 'not_empty'=>true, 'max_length'=>'255', 'values'=>$when_values));
|
|
|
+ $pdo = DB::getPDO();
|
|
|
+ $sth = $pdo->prepare("
|
|
|
+ insert into `CRM_NOTIFY` (
|
|
|
+ `who`,
|
|
|
+ `what`,
|
|
|
+ `when`,
|
|
|
+ `_created`
|
|
|
+ ) values (
|
|
|
+ :who,
|
|
|
+ :what,
|
|
|
+ :when,
|
|
|
+ NOW()
|
|
|
+ )
|
|
|
+ ");
|
|
|
+ $bindValues = array();
|
|
|
+ $bindValues['who'] = array($usrLogin, PDO::PARAM_STR);
|
|
|
+ $bindValues['what'] = array($what, PDO::PARAM_STR);
|
|
|
+ $bindValues['when'] = array($when, PDO::PARAM_STR);
|
|
|
+ $pdo->bindValues($sth, $bindValues);
|
|
|
+ //DBG::_(true, true, "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ $sth->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getUserReminders($usrLogin) {
|
|
|
+ $pdo = DB::getPDO();
|
|
|
+ $sth = $pdo->prepare("
|
|
|
+ select n.*
|
|
|
+ from `CRM_NOTIFY` n
|
|
|
+ where n.`who` = '{$usrLogin}'
|
|
|
+ ");
|
|
|
+ $sth->execute();
|
|
|
+ $reminders = $sth->fetchAll();
|
|
|
+ return $reminders;
|
|
|
}
|
|
|
|
|
|
public function reinstallAction() {
|