17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page_edit_fns.inc';
42 parent::__construct($assetid);
43 unset($this->static_screens[
'settings']);
44 unset($this->static_screens[
'preview']);
45 unset($this->static_screens[
'lookupValues']);
46 unset($this->static_screens[
'metadata']);
47 unset($this->static_screens[
'metadataSchemas']);
48 unset($this->static_screens[
'workflow']);
49 unset($this->static_screens[
'tagging']);
50 unset($this->static_screens[
'dependants']);
51 unset($this->static_screens[
'linking']);
52 unset($this->static_screens[
'roles']);
53 unset($this->static_screens[
'layouts']);
70 $wa = $asset->writeAccess(
'attributes');
72 $current_product = $asset->getCurrentProduct();
73 if (empty($current_product)) {
74 echo translate(
'suite_not_registered');
76 $o->openField(translate(
'suite_system_id'));
77 echo array_get_index($current_product,
'systemid',
'');
79 $o->openField(translate(
'suite_system_name'));
80 $system_name = array_get_index($current_product[
'connection'],
'name',
'');
82 echo text_box($prefix.
'_current_name', $system_name, 30);
87 $o->openField(translate(
'suite_system_url'));
88 echo array_get_index($current_product,
'url',
'');
93 $o->openField(translate(
'suite_tools_register'));
95 if (!empty($current_product)) {
96 $click =
'if (this.checked === true) { if (!confirm(\''.translate(
'js_confirm_msg').
'\')) { this.checked=
false }};
';
98 echo check_box($prefix.'_register
', '1
', FALSE, $click);
99 echo label(translate('suite_register
'), $prefix.'_register
');
101 if (!empty($current_product)) {
102 $o->openField(translate('suite_tools_deregister
'));
103 echo check_box($prefix.'_deregister
', '1
', FALSE, 'if (this.checked ==
true) {
if (!confirm(\
''.translate(
'js_confirm_msg').
'\')) { this.checked =
false } };
');
104 echo label(translate('suite_deregister
'), $prefix.'_deregister
');
111 }//end paintSystemId()
124 function processSystemId(&$asset, &$o, $prefix)
126 $wa = $asset->writeAccess('attributes
');
127 $current_product = $asset->getCurrentProduct();
129 $register = array_get_index($_POST, $prefix.'_register
', '0
');
130 $deregister = array_get_index($_POST, $prefix.'_deregister
', '0
');
132 if ($deregister == '1
' && !empty($current_product)) {
133 $suiteid = array_get_index($current_product, 'suiteid
', '0
');
134 if (!empty($suiteid)) {
135 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
137 $asset->removeProduct($suiteid, TRUE);
138 } catch (PDOException $e) {
139 $GLOBALS['SQ_SYSTEM
']->doTransaction('ROLLBACK
');
142 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
144 // Remove happened, so finish processing (you cannot deregister and then register on the same screen)
149 if ($register == '1
') {
150 if (empty($current_product)) {
151 // New product, register.
152 $systemid = self::_getSystemid();
153 $url = $asset->getUrl();
155 'name
' => 'Squiz Matrix
',
157 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
159 $suiteid = $asset->registerProduct($systemid, 'Squiz Matrix
', $url, $connection);
160 $asset->updateProduct($suiteid, 'is_current
', TRUE);
161 $asset->generateSystemKeyPair();
162 } catch (PDOException $e) {
163 $GLOBALS['SQ_SYSTEM
']->doTransaction('ROLLBACK
');
166 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
168 // New systemid, keep old details.
169 $newid = self::_getSystemid();
170 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
172 $asset->updateProduct($current_product['suiteid
'], 'systemid
', $newid);
173 } catch (PDOException $e) {
174 $GLOBALS['SQ_SYSTEM
']->doTransaction('ROLLBACK
');
177 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
181 // Finally, save the name by reloading the current product.
182 $current_product = $asset->getCurrentProduct();
183 if ($wa && !empty($current_product)) {
184 $connection = array_get_index($current_product, 'connection
', array());
185 $current_name = array_get_index($connection, 'name
', '');
186 $new_name = array_get_index($_POST, $prefix.'_current_name
', '');
187 if (!empty($new_name) && $new_name !== $current_name) {
189 $connection['name
'] = $new_name;
190 $asset->updateProduct($current_product['suiteid
'], 'connection
', $connection);
192 // Send the request to other systems
194 'updateType
' => 'name
',
195 'updateValue
' => $new_name,
197 $liveProducts = $asset->getLiveProducts();
198 foreach ($liveProducts as $liveProduct) {
199 $response = $asset->sendRequest($liveProduct['suiteid
'], 'xml
', 'SquizSuite
', 'suiteProductUpdate
', $message);
206 }//end processSystemId()
215 private function _getSystemid()
217 $systemid = 'matrix-
';
218 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
';
219 $charsLen = strlen($chars);
221 for ($i = 0; $i < $randLen; $i++) {
222 $idx = rand(0, ($charsLen - 1));
223 $systemid .= $chars[$idx];
228 }//end _getSystemid()
241 function paintProducts(&$asset, &$o, $prefix)
243 $wa = $asset->writeAccess('attributes
');
246 <table class="sq-backend-table" style="width:100%">
248 <td class="sq-backend-table-header" width="20%"><?php echo translate('suite_system_id
'); ?></td>
249 <td class="sq-backend-table-header" width="50%"><?php echo translate('suite_system_name
'); ?></td>
250 <td class="sq-backend-table-header" width="20%"><?php echo translate('suite_system_type
'); ?></td>
251 <td class="sq-backend-table-header" width="20%"><?php echo translate('suite_status
'); ?></td>
252 <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('suite_activate
'); ?></td><?php } ?>
253 <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('delete'); ?>?</td><?php } ?>
257 $products = $asset->getProducts(FALSE, TRUE);
258 foreach ($products as $product) {
259 $id = $product['suiteid
'];
263 echo $product['systemid
'];
266 echo array_get_index($product['connection
'], 'name
', '');
269 echo $product['type
'];
272 echo ucwords($product['status
']);
277 if ($product['type
'] != 'unknown
' && $product['status
'] !== 'live
' && $product['status
'] !== 'failed
') {
278 check_box($prefix.'_activate[]
', $id);
283 if ($product['sync_status
'] === 'D
') {
286 check_box($prefix.'_remove[]
', $id, $checked);
291 // Further for Matrix products, add a username/password field.
292 if ($wa && $product['type
'] == 'Squiz Matrix
') {
294 echo '<td>
'.translate('username
').'</td>
';
295 echo '<td colspan=
"2">
';
296 echo text_box($prefix.'_username[
'.$product['suiteid
'].']
', array_get_index($product['connection
'], 'username
', ''), 30);
298 echo '<td>
'.translate('password
').'</td>
';
299 echo '<td colspan=
"2">
';
300 echo password_box($prefix.'_password[
'.$product['suiteid
'].']
', array_get_index($product['connection
'], 'password
', ''), 30);
310 }//end paintProducts()
323 function processProducts(&$asset, &$o, $prefix)
325 $activate = array_get_index($_POST, $prefix.'_activate
', Array());
326 $remove = array_get_index($_POST, $prefix.'_remove
', Array());
328 foreach ($activate as $activate_system) {
329 // If found here, then removing the system, so skip activation...
330 if (in_array($activate_system, $remove)) continue;
332 $response = $asset->sendMessage($activate_system, 'suiteConnectAck
');
334 if (!headers_sent()) {
335 header('Content-type: text/html;
');
338 if ($response['curlInfo
']['http_code
'] !== 200) {
339 trigger_localised_error('SQS0021
', E_USER_WARNING, $response['curlInfo
']['http_code
']);
343 $live_products = $asset->getProducts(FALSE, FALSE, array('Squiz Update
'), array('live
'));
344 $live_prod_ids = array();
345 foreach ($live_products as $live_product) {
346 $live_prod_ids[] = $live_product['suiteid
'];
349 $updateSyncStatus = TRUE;
350 $productsToSyncAfter = array_diff($live_prod_ids, $remove);
351 if (empty($productsToSyncAfter) === TRUE) {
352 $updateSyncStatus = FALSE;
355 foreach ($remove as $remove_system) {
356 if ($updateSyncStatus === TRUE) {
357 $asset->updateProduct($remove_system, 'sync_status
', 'D
');
359 $asset->removeProduct($remove_system);
363 // Matrix usernames and passwords save.
364 $usernames = array_get_index($_POST, $prefix.'_username
', array());
365 $passwords = array_get_index($_POST, $prefix.'_password
', array());
367 foreach ($usernames as $suiteid => $username) {
368 $product = $asset->getProduct($suiteid);
369 if (!empty($product)) {
370 $current_user = array_get_index($product['connection
'], 'username
', '');
371 if (!empty($username) && $username !== $current_user) {
372 $connection = array_get_index($product, 'connection
', array());
373 $connection['username
'] = $username;
374 $asset->updateProduct($suiteid, 'connection
', $connection);
379 foreach ($passwords as $suiteid => $password) {
380 $product = $asset->getProduct($suiteid);
381 if (!empty($product)) {
382 $current_pass = array_get_index($product['connection
'], 'password
', '');
383 if (!empty($password) && $password !== $current_pass) {
384 $connection = array_get_index($product, 'connection
', array());
385 $connection['password
'] = $password;
386 $asset->updateProduct($suiteid, 'connection
', $connection);
393 }//end processProducts()
406 function paintRegister(&$asset, &$o, $prefix)
408 $wa = $asset->writeAccess('attributes
');
409 $current = $asset->getCurrentProduct();
411 if ($wa && !empty($current)) {
412 echo translate('suite_new_product_url
').' ';
413 text_box($prefix.'_new_product
', '');
418 }//end paintRegister()
431 function processRegister(&$asset, &$o, $prefix)
433 $product_url = array_get_index($_POST, $prefix.'_new_product
', '');
434 $product_url = trim($product_url);
435 $product_url = rtrim($product_url, '/
');
437 if (!empty($product_url)) {
438 if (strpos($product_url, 'http:
439 $product_url =
'http://'.$product_url;
442 if (strpos($product_url,
'__api') !== (strlen($product_url) - 5)) {
443 $product_url .=
'/__api';
446 $response = $asset->sendMessage($product_url,
'suiteConnect');
448 if ($response[
'curlInfo'][
'http_code'] === 404) {
450 $product_url = substr($product_url, 0, strpos($product_url,
'__api'));
451 $response = $asset->sendMessage($product_url,
'suiteConnect');
454 if ($response[
'curlInfo'][
'http_code'] === 200) {
456 $systemType =
'unknown';
457 $systemName =
'Unknown System';
458 $connection = array(
'name' => $systemName);
459 $suiteid = $asset->registerProduct($tempid, $systemType, $product_url, $connection);
460 $asset->updateProduct($suiteid,
'status',
'pending');
462 trigger_localised_error(
'SQS0020', E_USER_WARNING, $response[
'curlInfo'][
'http_code']);