Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
79.17% |
57 / 72 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| _get_login_place | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
5.01 | |||
| register_login_event | |
77.78% |
14 / 18 |
|
0.00% |
0 / 1 |
8.70 | |||
| _get_guest_place | |
73.91% |
17 / 23 |
|
0.00% |
0 / 1 |
10.44 | |||
| register_guest_event | |
77.78% |
14 / 18 |
|
0.00% |
0 / 1 |
8.70 | |||
| 1 | <?php |
| 2 | include_once __DIR__."/registry.php"; |
| 3 | |
| 4 | /** |
| 5 | * Resolve place for user login. Uses central DB (PLACE). |
| 6 | * |
| 7 | * @param \ConxHelper $conx Connection helper (global used). |
| 8 | * @param array|null $place Output: place row. |
| 9 | * @param array $event Login event with 'place' key. |
| 10 | * @return int ApplicationError code. |
| 11 | */ |
| 12 | function _get_login_place(\ConxHelper $conx, &$place, &$event){ |
| 13 | $retval = ApplicationError::Success; |
| 14 | |
| 15 | if (success($retval)){ |
| 16 | $results = []; |
| 17 | $res = $conx->global->query('PLACE', [ 'objid' => $event['place'], 'status' => 'AC' ], $results); |
| 18 | if ($res){ |
| 19 | if (count($results) > 0){ |
| 20 | $place = $results[0]; |
| 21 | } |
| 22 | |
| 23 | if (!$place){ |
| 24 | addlog(__FILE__, LogLevel::Error, "No active place found for user login: '".$event['place']."'"); |
| 25 | $retval = ApplicationError::NotFound; |
| 26 | } |
| 27 | } |
| 28 | else { |
| 29 | $retval = ApplicationError::Database; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return $retval; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Register login event (user login). Uses central DB. |
| 38 | * |
| 39 | * @param \ConxHelper $conx Connection helper. |
| 40 | * @param string $session Session id. |
| 41 | * @param array $event Event with 'place', 'login', 'created'. |
| 42 | * @return int ApplicationError code. |
| 43 | */ |
| 44 | function register_login_event(\ConxHelper $conx, $session, &$event){ |
| 45 | $retval = ApplicationError::Success; |
| 46 | |
| 47 | // obtain the place related information |
| 48 | if (success($retval)){ |
| 49 | $retval = _get_login_place($conx, $place, $event); |
| 50 | } |
| 51 | |
| 52 | if (success($retval)){ |
| 53 | $dstpath = AppConstants::RegLogPath(); |
| 54 | if (!file_exists($dstpath) && !mkdir($dstpath, 0775)){ |
| 55 | addlog(__FILE__, LogLevel::Error, "Could not create local registry log folder in '".$dstpath."'"); |
| 56 | $error = error_get_last(); |
| 57 | if ($error) addlog(__FILE__, LogLevel::Debug, $error['message']); |
| 58 | } |
| 59 | |
| 60 | if (is_dir($dstpath)){ |
| 61 | $dstfile = sprintf('%s/%05d_ticket_activity.csv', $dstpath, $place['objid']); |
| 62 | |
| 63 | $lineinfo = [ |
| 64 | 'session' => $session |
| 65 | ]; |
| 66 | |
| 67 | if ($event['login'] == '1'){ |
| 68 | append_logline($dstfile, $event['created'], $place['objid'], LogEvent::UsrLogin, $lineinfo); |
| 69 | } |
| 70 | else { |
| 71 | append_logline($dstfile, $event['created'], $place['objid'], LogEvent::UsrLogout, $lineinfo); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return $retval; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Resolve place for guest login. Uses central DB (QRSCAN, PLACE). |
| 81 | * |
| 82 | * @param \ConxHelper $conx Connection helper (global used). |
| 83 | * @param array|null $place Output: place row. |
| 84 | * @param array $event Login event with 'qrcode' key (QRSCAN.objid from scan). |
| 85 | * @return int ApplicationError code. |
| 86 | */ |
| 87 | function _get_guest_place(\ConxHelper $conx, &$place, &$event){ |
| 88 | $retval = ApplicationError::Success; |
| 89 | |
| 90 | if (success($retval)){ |
| 91 | $qrcode = null; |
| 92 | $results = []; |
| 93 | $res = $conx->global->query('QRSCAN', [ 'objid' => $event['qrcode'], 'status' => 'AC' ], $results); |
| 94 | if ($res){ |
| 95 | if (count($results) > 0){ |
| 96 | $qrcode = $results[0]; |
| 97 | } |
| 98 | |
| 99 | if (!$qrcode){ |
| 100 | addlog(__FILE__, LogLevel::Error, "No active table found for guest login: '".$event['qrcode']."'"); |
| 101 | $retval = ApplicationError::NotFound; |
| 102 | } |
| 103 | } |
| 104 | else { |
| 105 | $retval = ApplicationError::Database; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (success($retval)){ |
| 110 | $results = []; |
| 111 | $res = $conx->global->query('PLACE', [ 'objid' => $qrcode['place'], 'status' => 'AC' ], $results); |
| 112 | if ($res){ |
| 113 | if (count($results) > 0){ |
| 114 | $place = $results[0]; |
| 115 | } |
| 116 | |
| 117 | if (!$place){ |
| 118 | addlog(__FILE__, LogLevel::Error, "No active place found for guest login on table: '".$event['qrcode']."'"); |
| 119 | $retval = ApplicationError::NotFound; |
| 120 | } |
| 121 | } |
| 122 | else { |
| 123 | $retval = ApplicationError::Database; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return $retval; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Register guest login event. Uses central DB. |
| 132 | * |
| 133 | * @param \ConxHelper $conx Connection helper. |
| 134 | * @param string $session Session id. |
| 135 | * @param array $event Event with 'qrcode', 'login', 'created'. |
| 136 | * @return int ApplicationError code. |
| 137 | */ |
| 138 | function register_guest_event(\ConxHelper $conx, $session, &$event){ |
| 139 | $retval = ApplicationError::Success; |
| 140 | |
| 141 | // obtain the qrcode related information |
| 142 | if (success($retval)){ |
| 143 | $retval = _get_guest_place($conx, $place, $event); |
| 144 | } |
| 145 | |
| 146 | if (success($retval)){ |
| 147 | $dstpath = AppConstants::RegLogPath(); |
| 148 | if (!file_exists($dstpath) && !mkdir($dstpath, 0775)){ |
| 149 | addlog(__FILE__, LogLevel::Error, "Could not create local registry log folder in '".$dstpath."'"); |
| 150 | $error = error_get_last(); |
| 151 | if ($error) addlog(__FILE__, LogLevel::Debug, $error['message']); |
| 152 | } |
| 153 | |
| 154 | if (is_dir($dstpath)){ |
| 155 | $dstfile = sprintf('%s/%05d_ticket_activity.csv', $dstpath, $place['objid']); |
| 156 | |
| 157 | $lineinfo = [ |
| 158 | 'session' => $session |
| 159 | ]; |
| 160 | |
| 161 | if ($event['login'] == '1'){ |
| 162 | append_logline($dstfile, $event['created'], $place['objid'], LogEvent::GstLogin, $lineinfo); |
| 163 | } |
| 164 | else { |
| 165 | append_logline($dstfile, $event['created'], $place['objid'], LogEvent::GstLogout, $lineinfo); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return $retval; |
| 171 | } |
| 172 | |
| 173 | ?> |