Prechádzať zdrojové kódy

added generate user reminders using Przypomnij

Piotr Labudda 10 rokov pred
rodič
commit
1c171bebdc
2 zmenil súbory, kde vykonal 207 pridanie a 0 odobranie
  1. 197 0
      SE/se-lib/Route/Notify.php
  2. 10 0
      SE/se-lib/V.php

+ 197 - 0
SE/se-lib/Route/Notify.php

@@ -1,6 +1,7 @@
 <?php
 
 Lib::loadClass('RouteBase');
+Lib::loadClass('Przypomnij');
 
 /*
 # Nofitication system:
@@ -30,6 +31,202 @@ class Route_Notify extends RouteBase {
 		SE_Layout::dol();
 	}
 
+	public function generateUserRemindersAction() {
+		$usrLogin = User::getLogin();
+		$usrLogin = (isset($_GET['usrLogin']))? V::get('usrLogin', '', $_GET, 'login') : $usrLogin;
+		if (!$usrLogin) die("Wrong user login!");
+
+		$userReminders = $this->getUserReminders($usrLogin);
+		if (empty($userReminders)) die("Brak zdefiniowanych powiadomień");
+
+		header('Content-Type: text/html; charset="UTF-8"');
+		$this->generateUserReminders($usrLogin, $userReminders);
+	}
+
+	public function generateUserReminders($usrLogin, $userReminders) {
+		echo '<html>';
+		echo '<body>';
+		echo '<div>';
+		?>
+<h1 style="<?php echo $this->inlineCss('h1'); ?>">Powiadomienia dla <code><?php echo $usrLogin; ?></code></h1>
+<table rules="all" cellspacing="0" style="border-color:#bbb;" cellpadding="8">
+<?php foreach ($userReminders as $reminder) : ?>
+	<tr>
+		<td colspan="4" style="<?php echo $this->inlineCss('td.header'); ?>"><strong><?php echo $this->printValue('what', $reminder['what']); ?></strong></td>
+	</tr>
+	<?php $lp = 0; foreach ($this->getTodoForUserReminder($usrLogin, $reminder['what']) as $todo) : ?>
+		<tr>
+			<td style="<?php echo $this->inlineCss('td.lp'); ?>"><?php echo ++$lp; ?></td>
+			<td style="<?php echo $this->inlineCss('td.' . $todo['_l_app_class']); ?>">
+				<?php echo $todo['_l_app_date']; ?>
+				<br><i style="color:#333;"><?php echo $todo['_l_app']; ?></i>
+				<?php if ($todo['ID'] > 0) : ?>
+					<br><a href="<?php echo $this->editLink($todo); ?>" target="_blank" style="<?php echo $this->inlineCss('a'); ?>">Edytuj rekord <?php echo $todo['ID']; ?></a>
+				<?php endif; ?>
+			</td>
+			<td style="<?php echo $this->inlineCss('td.info'); ?>"><?php echo $todo['L_APPOITMENT_INFO']; ?></td>
+			<td style="<?php echo $this->inlineCss('td.record-info'); ?>">
+				<br><?php echo $todo['_title']; ?>
+			</td>
+<?php if (V::get('DBG', '', $_GET)) : ?>
+			<td style="<?php echo $this->inlineCss('td.record-desc'); ?>"><pre style="border:1px solid red;max-height:80px;overflow:scroll"><?php print_r($todo); ?></pre></td>
+<?php endif; ?>
+		</tr>
+	<?php endforeach; ?>
+<?php endforeach; ?>
+</table>
+<?php
+		echo '</div>';// .container
+		echo '</body>';
+		echo '</html>';
+	}
+
+	public function editLink($todo) {
+		$idTblZasob = 0;
+		$idRecord = 0;
+		if ('zasob' == $todo['_task_type']) {
+			$idTblZasob = $todo['_idZasobTable'];
+			$idRecord = $todo['ID'];
+		}
+		if (!$idTblZasob || !$idRecord) return '#';
+
+		$urlParts = array();
+		$urlParts[] = (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']))? $_SERVER['HTTP_X_FORWARDED_PROTO'] : V::get('REQUEST_SCHEME', 'http', $_SERVER);
+		$urlParts[] = '://';
+		$urlParts[] = $_SERVER['SERVER_NAME'];
+		$urlParts[] = $_SERVER['SCRIPT_URL'];
+		// https://biuro.biall-net.pl/dev-pl/se-master/index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=1466#EDIT/3954
+		$urlParts[] = "?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$idTblZasob}#EDIT/{$idRecord}";
+		return implode("", $urlParts);
+	}
+
+	public function inlineCss($cssSelector) {
+		$baseCss = array();
+		$baseCss['font-family'] = 'Arial, Helvetica, sans-serif';
+		$baseCss['font-size'] = 'small';
+		$baseCss['color'] = '#333';
+
+		$customCss = array(
+			'h1' => array(),
+			'td.header' => array('background' => '#eee'),
+			'td.date-base' => array('white-space' => 'nowrap'),
+			'td.lp' => array('color' => 'silver'),
+			'a' => array('color' => '#337ab7', 'text-decoration' => 'none')
+		);
+
+		$css = $baseCss;
+		if (array_key_exists($cssSelector, $customCss)) $css = V::extend($css, $customCss[$cssSelector]);
+		if ('td.date-' == substr($cssSelector, 0, 8)) {
+			$css = V::extend($css, $customCss['td.date-base']);
+			$css = V::extend($css, array('color' => $this->getTodoDateCssColor(substr($cssSelector, 3))));
+		}
+
+		$inlineCss = array();
+		foreach ($css as $cssPropName => $cssValue) {
+			if (true === $cssValue) {
+				if (!array_key_exists($cssPropName, $baseCss)) continue;
+				$cssValue = $baseCss[$cssPropName];
+			}
+			$inlineCss[] = "{$cssPropName}:{$cssValue}";
+		}
+		return implode(";", $inlineCss);
+	}
+
+	public function getTodoDateCssColor($lAppClass) {
+		$color = '#000';
+		switch ($lAppClass) {
+			case 'date-PO_TERMINIE': $color = '#FD4242'; break;
+			case 'date-DZISIAJ': $color = '#34B934'; break;
+			case 'date-W_CIAGU_7_DNI': $color = '#C58B1F'; break;
+			case 'date-PO_7_DNIACH': $color = '#87847D'; break;
+		}
+		return $color;
+	}
+
+	public function getTodoForUserReminder($usrLogin, $reminderWhat) {
+		$listTodo = array();
+		if ('msgs' == $reminderWhat) {
+//			$todo = array();
+//			$todo['_title'] = 'test msgs id';
+//			$todo['L_APPOITMENT_INFO'] = 'test msgs id';
+//			$listTodo[] = $todo;
+		}
+		else if ('l_app_projekty' == $reminderWhat) {
+			$tasks = $this->getPrzypomnijTasks($usrLogin);
+			foreach ($tasks as $task) {
+				if (empty($task['_l_app_date']) || '0000-00-00' == $task['_l_app_date']) continue;
+				if ('projekt' != $task['_task_type']) continue;
+				//$task['DESC'] = $task['A_PROBLEM_DESC'];
+				$listTodo[] = $task;
+			}
+		}
+		else if ('l_app_koresp' == $reminderWhat) {
+			$tasks = $this->getPrzypomnijTasks($usrLogin);
+			foreach ($tasks as $task) {
+				if (empty($task['_l_app_date']) || '0000-00-00' == $task['_l_app_date']) continue;
+				if ('koresp' != $task['_task_type']) continue;
+				//$task['DESC'] = $task['A_PROBLEM_DESC'];
+				$listTodo[] = $task;
+			}
+		}
+		else if ('l_app_zadania' == $reminderWhat) {
+			$tasks = $this->getPrzypomnijTasks($usrLogin);
+			foreach ($tasks as $task) {
+				if (empty($task['_l_app_date']) || '0000-00-00' == $task['_l_app_date']) continue;
+				if ('task' != $task['_task_type']) continue;
+				//$task['DESC'] = $task['A_PROBLEM_DESC'];
+				$listTodo[] = $task;
+			}
+		}
+		else if ('l_app_procesy' == $reminderWhat) {
+			$tasks = $this->getPrzypomnijTasks($usrLogin);
+			foreach ($tasks as $task) {
+				if (empty($task['_l_app_date']) || '0000-00-00' == $task['_l_app_date']) continue;
+				if ('proces' != $task['_task_type']) continue;
+				$listTodo[] = $task;
+			}
+		}
+		else if ('l_app_zasoby' == $reminderWhat) {
+			$tasks = $this->getPrzypomnijTasks($usrLogin);
+			foreach ($tasks as $task) {
+				if (empty($task['_l_app_date']) || '0000-00-00' == $task['_l_app_date']) continue;
+				if ('zasob' != $task['_task_type']) continue;
+				$listTodo[] = $task;
+			}
+		}
+		return $listTodo;
+	}
+
+	public function getPrzypomnijTasks($usrLogin) {
+		static $_tasks = array();
+		if (empty($_tasks)) {
+			$przypomnij = new Przypomnij();
+			$przypomnij->setRecurseLimit(3);
+			$przypomnij->fetchData();
+			$przypomnij->setFltrUser($usrLogin);
+
+			$tasks = $przypomnij->getTasksByDate();
+			$usrGroupNames = User::getLdapGroupsNames();
+			foreach ($tasks as $task) {
+				if (!$task->_show) continue;
+				if (
+					$task->A_CLASSIFIED != ''
+					and !(in_array($task->A_CLASSIFIED, $usrGroupNames))
+					and $task->A_ADM_COMPANY != ''
+					and !(in_array($task->A_ADM_COMPANY, $usrGroupNames))
+					// !($allowedUsers[$task->_l_app]) - to jest bez sensu - wystarczy widocznosc sprawy?
+				) {
+					continue;
+				}
+				$task->_l_app_class = $przypomnij->getTaskDateFltrType($task->_l_app_date);
+				$task->_idZasobTable = $przypomnij->getZasobIdByType($task->_task_type);
+
+				$_tasks[] = (array)$task;
+			}
+		}
+		return $_tasks;
+	}
+
 	public function removeUserTableReminder($args) {
 		$usrLogin = User::getLogin();
 		$who  = V::validate('who',  $args, array('type'=>'word', 'equal'=>$usrLogin, 'error_msg_equal'=>"Brak uprawnień do wprowadzania zmian w powiadomieniach innych użytwkoników"));

+ 10 - 0
SE/se-lib/V.php

@@ -64,6 +64,16 @@ class V {
 					}
 				}
 				break;
+			case 'login':// [a-zA-Z.-_]
+				if (is_scalar($from)) {
+					$ret = $from;
+					settype($ret, 'string');
+					$ret = trim($ret);
+					if (!preg_match("/^[a-zA-Z.-_]*$/", $ret, $matches)) {
+						$ret = null;
+					}
+				}
+				break;
 			case 'int':
 			case 'integer':
 				if (is_scalar($from)) {