function artistAdd($num = 1) { $request = "http://localhost/dev/yahoo_music/dev/artist.php"; // $request = "http://p1.osp.hki.yahoo.com/admin/artist.php"; for ($index = 0; $index <= $num; $index++) { $artistcode = "artistcode" . mt_rand(99999, 10000000); $artistname = "artistname" . mt_rand(99999, 10000000); $artistname_eng = "artistname_eng" . mt_rand(99999, 10000000); $initial = chr(mt_rand(ord('a'), ord('z'))); $postargs = "act=AddSubmit&artistcode={$artistcode}&artistname={$artistname}&artistname_eng={$artistname_eng}&initial={$initial}"; doPost($request, $postargs); } echo "success submit {$num} request "; }
function doSchedule($deviceId, $sch) { if (is_string($sch)) { $days = explode(":", $sch); foreach ($days as $day) { $result = doPost($deviceId, "receiveSch", $day); if ($result != "Success") { break; } } return $result; } else { return "Invalid schedule"; } }
function google_auth($auth, $email, $pass) { $gacookie = "gacookie"; $url = $auth; $postdata = "Email=" . $email . "&Passwd=" . $pass . "&accountType=GOOGLE&service=apps"; $referer = 'https://www.google.com/accounts/ClientLogin'; $result = doPost(compact('gacookie', 'postdata', 'url', 'referer')); ereg('Auth=(.*)', $result, $googToken); $Token = $googToken[1]; if ($Token) { return array(True, $Token); } else { return array(False); } }
/** * 触发关联动作 * * @author young * @name 触发关联动作 * @version 2014.02.12 young */ public function hookAction() { $collection_id = isset($_REQUEST['__COLLECTION_ID__']) ? trim($_REQUEST['__COLLECTION_ID__']) : ''; $collectionInfo = $this->_collection->findOne(array('_id' => myMongoId($collection_id), 'project_id' => $this->_project_id)); if ($collectionInfo != null) { try { $postDatas = array('__PROJECT_ID__' => $this->_project_id, '__COLLECTION_ID__' => $collection_id); $url = $collectionInfo['hook']; $hookKey = $collectionInfo['hookKey']; $sign = dataSignAlgorithm($postDatas, $hookKey); $postDatas['__SIGN__'] = $sign; $response = doPost($url, $postDatas); if ($response === false) { return $this->msg(false, '网络请求失败'); } $this->_collection->update(array('_id' => myMongoId($collection_id)), array('$set' => array('hookLastResponseResult' => $response))); return $this->msg(true, '触发联动操作成功'); } catch (\Exception $e) { return $this->msg(false, $e->getMessage()); } } else { return $this->msg(false, '触发联动操作失败'); } }
if (isset($mReturn->output[0])) { echo '<h3>Checking if Friends with User #' . $mReturn->output[0]->user_id . ' [friend.isFriend]</h3>'; $mReturn = doPost('friend.isFriend', array('friend_user_id' => $mReturn->output[0]->user_id)); echo '<pre>' . print_r($mReturn, true) . '</pre>'; } echo '<h3>Updating Users Status [user.updateStatus]</h3>'; $mReturn = doPost('user.updateStatus', array('user_status' => 'This is a test status update from an application... [' . uniqid() . ']')); echo '<pre>' . print_r($mReturn, true) . '</pre>'; echo '<h3>Getting Photos [photo.getPhotos]</h3>'; $mReturn = doPost('photo.getPhotos'); echo '<pre>' . print_r($mReturn, true) . '</pre>'; echo '<h3>Getting New Notifications Count [notification.getNewCount]</h3>'; $mReturn = doPost('notification.getNewCount'); echo '<pre>' . print_r($mReturn, true) . '</pre>'; echo '<h3>Getting Notifications [notification.get]</h3>'; $mReturn = doPost('notification.get'); echo '<pre>' . print_r($mReturn, true) . '</pre>'; echo '<h3>Getting New Mail Count [mail.getNewCount]</h3>'; $mReturn = doPost('mail.getNewCount'); echo '<pre>' . print_r($mReturn, true) . '</pre>'; ?> </body> </html>
function addCase($inbound) { $case_post_link = ''; // initialize ... // // STEP 1 - find (or create) Customer object // $customers = lookForCustomer($inbound['email']); $new_customer = false; if (count($customers) !== 0) { $case_post_link = $customers[0]->_links->cases->href; } else { // assemble address! $address = assembleAddress($inbound); $customer = array('first_name' => $inbound['first_name'], 'last_name' => $inbound['last_name'], 'emails' => array(array('type' => 'home', 'value' => $inbound['email'])), 'phone_numbers' => array(array('type' => 'home', 'value' => $inbound['phone'])), 'addresses' => array(array('type' => 'home', 'value' => $address))); if (isset($inbound['community'])) { if (!isset($customer['custom_fields'])) { $customer['custom_fields'] = array(); } $customer['custom_fields']['community'] = $inbound['community']; } $response = doPost('/api/v2/customers', json_encode($customer)); $case_post_link = $response->_links->cases->href; $new_customer = true; } // // STEP 2 - build message // $message = ''; $message .= 'How long have you been attending?'; $message .= "\n- " . ($inbound['howlongattending'] ? $inbound['howlongattending'] : '(empty)'); if ($inbound['howlongattending'] == 'Other') { $message .= ': ' . ($inbound['howlongattending-other'] ? $inbound['howlongattending-other'] : '(empty)'); } $message .= "\n\n"; $message .= 'How can we help?'; if (isset($inbound['help']) && is_array($inbound['help']) && count($inbound['help'])) { foreach ($inbound['help'] as $item) { $message .= "\n- {$item}"; if (preg_match('/\\bmeet\\b.+\\bleader\\b/', $item)) { $message .= "\n- - " . ($inbound['meet-leader'] ? $inbound['meet-leader'] : '(empty)'); } elseif (preg_match('/\\blike\\b.+\\bprayer\\b/', $item)) { $message .= "\n- - " . ($inbound['prayer-request'] ? $inbound['prayer-request'] : '(empty)'); } } } else { $message .= "\n- (none selected)"; } $message .= "\n\n"; $message .= 'Serving ministries...'; if (isset($inbound['ministry']) && is_array($inbound['ministry']) && count($inbound['ministry'])) { foreach ($inbound['ministry'] as $item) { $message .= "\n- {$item}"; } } else { $message .= "\n- (none selected)"; } $message .= "\n\n"; $message .= 'Which Community do you live in or are you interested in checking out?'; $message .= "\n- " . ($inbound['community'] ? $inbound['community'] : '(empty)'); if (!$new_customer) { $message .= "\n"; $message .= "\n-------------"; $message .= "Warning: customer already existed! No customer information was updated!"; $message .= "\n-------------"; } $message .= "\n\n"; $message .= "\n-------------"; /* $message .= "All inbound information: "; $message .= "\n"; $message .= print_r($inbound, true); */ // // STEP 3 - create Case // $subject = $inbound['first_name']; if ($inbound['first_name'] && $inbound['last_name']) { $subject .= ' '; } $subject .= ' - wants to connect!'; // WITH MIKE 20150702 // TODO - extra credit - use whatever they use for desire... $subject = 'Connecting with Downtown Cornerstone Church'; if (isset($inbound['help']) && is_array($inbound['help']) && count($inbound['help']) === 1) { $subject = 'DCC - ' . $inbound['help'][0]; } $case = array('type' => 'email', 'subject' => $subject, 'priority' => 4, 'status' => 'open', 'message' => array('direction' => 'in', 'subject' => $subject, 'body' => $message, 'to' => '*****@*****.**', 'from' => $inbound['email'])); return doPost($case_post_link, json_encode($case)); }
$resultfilename = "result_" . $crashid . ".crash"; echo "Processing crash id " . $crashid . " ...\n"; echo " Downloading crash data ...\n"; $log = file_get_contents($getcrashdataurl . $crashid); if ($log !== false && strlen($log) > 0) { echo " Writing log data into temporary file ...\n"; $output = fopen($filename, 'w+'); fwrite($output, $log); fclose($output); echo " Symbolicating ...\n"; exec('./symbolicatecrash -o ' . $resultfilename . ' ' . $filename); unlink($filename); if (file_exists($resultfilename) && filesize($resultfilename) > 0) { echo " Sending symbolicated data back to the server ...\n"; $resultcontent = file_get_contents($resultfilename); $post_results = doPost('id=' . $crashid . '&log=' . urlencode($resultcontent)); if (is_string($post_results)) { if ($post_results == 'success') { echo ' SUCCESS!'; } } } echo " Deleting temporary files ...\n"; unlink($resultfilename); } } echo "\nDone\n\n"; } else { if ($content !== false) { echo "Nothing to do.\n\n"; }
function initRackTablesItem($objectDatas) { // zabbix item data $params = array('output' => 'extend'); $result = doPost('item.get', $params); $items = isset($result['result']) ? $result['result'] : array(); foreach ($items as $item) { usePreparedInsertBlade('item_information', array('itemid' => $item['itemid'], 'objectid' => $objectDatas[$item['hostid']], 'hostid' => $item['hostid'], 'name' => $item['name'], 'type' => $item['type'], 'key_' => $item['key_'], 'interfaceid' => $item['interfaceid'], 'delay' => $item['delay'], 'history' => $item['history'], 'trends' => $item['trends'], 'value_type' => $item['value_type'], 'trapper_hosts' => $item['trapper_hosts'], 'units' => $item['units'], 'multiplier' => $item['multiplier'], 'delta' => $item['delta'], 'snmp_community' => $item['snmp_community'], 'snmp_oid' => $item['snmp_oid'], 'snmpv3_securityname' => $item['snmpv3_securityname'], 'snmpv3_securitylevel' => $item['snmpv3_securitylevel'], 'snmpv3_authpassphrase' => $item['snmpv3_authpassphrase'], 'snmpv3_privpassphrase' => $item['snmpv3_privpassphrase'], 'snmpv3_authprotocol' => $item['snmpv3_authprotocol'], 'snmpv3_privprotocol' => $item['snmpv3_privprotocol'], 'snmpv3_contextname' => $item['snmpv3_contextname'], 'formula' => $item['formula'], 'error' => $item['error'], 'lastlogsize' => $item['lastlogsize'], 'logtimefmt' => $item['logtimefmt'], 'templateid' => $item['templateid'], 'valuemapid' => $item['valuemapid'], 'delay_flex' => $item['delay_flex'], 'params' => $item['params'], 'ipmi_sensor' => $item['ipmi_sensor'], 'data_type' => $item['data_type'], 'authtype' => $item['authtype'], 'username' => $item['username'], 'password' => $item['password'], 'publickey' => $item['publickey'], 'privatekey' => $item['privatekey'], 'mtime' => $item['mtime'], 'flags' => $item['flags'], 'filter' => $item['filter'], 'port' => $item['port'], 'description' => $item['description'], 'inventory_link' => $item['inventory_link'], 'lifetime' => $item['lifetime'], 'status' => $item['status'])); } }
Select Image: </div> <div class="table_right"> <input type="file" name="file" /> </div> </div> <div class="table_clear"> <input type="submit" value="Upload" class="button" /> </div> </form> <?php if (isset($_FILES['file'])) { if (!file_exists($_FILES['file']['tmp_name'])) { echo '<div class="error_message">File was not uploaded properly.</div>'; } else { $mReturn = doPost('photo.addPhoto', array('photo' => '@' . $_FILES['file']['tmp_name'] . ';type=' . $_FILES['file']['type'], 'photo_name' => basename($_FILES['file']['name']))); ?> <div class="message">Image successfully uploaded and sent to the API server.</div> <h3>API Server Output</h3> <?php echo '<pre>'; print_r($mReturn); echo '</pre>'; if (isset($mReturn->output->original)) { echo '<h3>Photo Output</h3>'; foreach ($mReturn->output as $sKey => $sImage) { if ($sKey == 'original') { continue; } echo '<img src="' . $sImage . '" /><br /><br />'; }
function updateItem($item) { # parameters $item['method'] = 'update_item'; # response return doPost($item); }
/** * Gets database statistics/information. * @param $email login email address at the license portal * @param $password password at the license portal * @param $dbName name of the new database * @return Zend_Http_Response HTTP response */ function getStats($email, $password, $dbName) { $postResponse = doPost("getStats.php", array('timeout' => SHORT_OPERATION_TIMEOUT), array('email' => $email, 'password' => md5($password), 'dbName' => $dbName)); return $postResponse; }
for ($i = 0; $i < 5; $i++) { if (i > 0) { $notify_pushids .= ','; } $notify_pushids .= $push_array[$i]; } } // add the crash data to the database if ($crash["logdata"] != "" && $crash["version"] != "" && $crash["applicationname"] != "" && $crash["bundleidentifier"] != "" && $acceptlog == true) { // check if we need to redirect this crash if ($hockeyappidentifier != '') { if (!isset($hockeyAppURL)) { $hockeyAppURL = "ssl://beta.hockeyapp.net/"; } // we assume all crashes in this xml goes to the same app, since it is coming from one client. so push them all at once to HockeyApp $result = doPost($hockeyAppURL . "api/2/apps/" . $hockeyappidentifier . "/crashes", utf8_encode($xmlstring)); // we do not parse the result, values are different anyway, so simply return unknown status echo xml_for_result(VERSION_STATUS_UNKNOWN); /* schliessen der Verbinung */ mysql_close($link); // HockeyApp doesn't support direct feedback, it requires the new client to do that. So exit right away. exit; } // is this a jailbroken device? $jailbreak = 0; if (strpos($crash["logdata"], "MobileSubstrate") !== false) { $jailbreak = 1; } // Since analyzing the log data seems to have problems, first add it to the database, then read it, since it seems that one is fine then // first check if the version status is not discontinued // check if the version is already added and the status of the version and notify status
<?php include_once 'langList.php'; include_once 'common.php'; echoStyle(); if (isset($_POST['strSource'], $_POST['strDest'])) { doPost($_POST['strSource'], $_POST['strDest']); } elseif (isset($_GET['lang'])) { $lang = strtolower($_GET['lang']); if ($lang != "") { if (!in_array("lang." . $lang . ".php", getLangFiles())) { if (preg_match("/^[a-zA-Z0-9_-]*\$/", $lang)) { showAddNew($lang); } else { badData("LANGUAGE (" . $lang . ") HAS INVALID CHARS"); } } else { badData("THAT LANGUAGE ALREADY EXISTS"); } } else { badData("NO LANGUAGE ENTERED"); } } else { badData("NO LANGUAGE ENTERED"); } function doPost($strSource, $strDest) { if (!in_array($strDest, getLangFiles())) { if (copy($strSource, $strDest)) { iniTable(); echo "<h1>File created successfully</h1>";
$headers = array('HTTP_HOST', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_CHARSET', 'HTTP_KEEP_ALIVE', 'HTTP_CONNECTION', 'HTTP_CACHE_CONTROL'); $request->method = $_SERVER['REQUEST_METHOD']; $request->url = $_SERVER['REQUEST_URI']; $request->host = $_SERVER['HTTP_HOST']; $request->protocol = $_SERVER['SERVER_PROTOCOL']; //$request->query = $_SERVER['QUERY_STRING']; $request->query = $_GET; //$request->headers = processHeaders($headers); $request->headers = getallheaders(); switch ($request->method) { case 'GET': doGet($request); break; case 'POST': $request->body = file_get_contents('php://input'); doPost($request); break; case 'PUT': $request->body = file_get_contents('php://input'); doPut($request); break; case 'DELETE': doDelete($request); break; default: echo $request->method, " not supported.\n"; break; } function doGet($request) { //echo '<pre>'; print_r($request); echo '</pre>';
<?php include_once 'langList.php'; include_once 'common.php'; echoStyle(); $iniKey = "public \$"; $iniValue = '"";'; $strKey = $iniKey; $strValue = $iniValue; if (isset($_POST['strKey'], $_POST['strValue'])) { $strKey = str_replace("\\", "", $_POST['strKey']); $strValue = str_replace("\\", "", $_POST['strValue']); //Validate $strMessage = validate($strKey, $strValue); if ($strMessage == '') { $strMessage = doPost($strKey, $strValue); $strKey = $iniKey; $strValue = $iniValue; } } iniTable(); ?> <h1 align="center">- Select Action -</h1><br> <strong>1 - Edit Language File:</strong> <select onchange="location = 'edit.php?lang='+this.options[this.selectedIndex].value;"> <option value="">Select lang file </option> <?php foreach (getLangFiles() as $key => $value) { echo "<option value=" . $value . ">" . $value . "</option>";
/** * Common method to handle POST method * * @param string $r_resource_cmd URL * @param array $r_resource_vars Array generated from URL * @param array $r_resource_filters Array generated from URL query string * @param array $r_post Post data * * @return mixed */ function r_post($r_resource_cmd, $r_resource_vars, $r_resource_filters, $r_post) { global $r_debug, $db_lnk, $authUser, $thumbsizes, $_server_domain_url; $emailFindReplace = $response = array(); $fields = 'created, modified'; $values = 'now(), now()'; $json = $sql = $is_return_vlaue = false; $uuid = ''; if (isset($r_post['uuid'])) { $uuid = $r_post['uuid']; } unset($r_post['temp_id']); unset($r_post['uuid']); unset($r_post['id']); switch ($r_resource_cmd) { case '/users/forgotpassword': //users forgot password $val_arr = array($r_post['email']); $user = executeQuery('SELECT * FROM users WHERE email = $1', $val_arr); if ($user) { $password = uniqid(); $val_arr = array(getCryptHash($password), $user['id']); pg_query_params($db_lnk, 'UPDATE users SET (password) = ($1) WHERE id = $2', $val_arr); $emailFindReplace = array('mail' => 'forgetpassword', '##USERNAME##' => $user['username'], '##PASSWORD##' => $password, 'to' => $user['email']); $response = array('success' => 'An email has been sent with your new password.'); sendMail($emailFindReplace); } else { $response = array('error' => 'Please enter valid email id.'); } break; case '/users': //Admin user add $table_name = 'users'; $val_arr = array($r_post['username'], $r_post['email']); $user = executeQuery('SELECT * FROM users WHERE username = $1 OR email = $2', $val_arr); if (!$user) { $sql = true; $table_name = 'users'; $r_post['password'] = getCryptHash($r_post['password']); $r_post['role_id'] = 2; // user $r_post['is_active'] = true; $r_post['is_email_confirmed'] = true; $r_post['role_id'] = 2; // user $r_post['initials'] = strtoupper(substr($r_post['username'], 0, 1)); $r_post['ip_id'] = saveIp(); } else { $msg = ''; if ($user['email'] == $r_post['email']) { $msg = 'Email address already exists. Your registration process is not completed. Please, try again.'; } else { if ($user['username'] == $r_post['username']) { $msg = 'Username already exists. Your registration process is not completed. Please, try again.'; } } $response = array('error' => $msg); } break; case '/users/register': //users register $table_name = 'users'; $val_arr = array($r_post['username'], $r_post['email']); $user = executeQuery('SELECT * FROM users WHERE username = $1 OR email = $2', $val_arr); if (!$user) { $sql = true; $table_name = 'users'; $r_post['password'] = getCryptHash($r_post['password']); $r_post['role_id'] = 2; // user $r_post['initials'] = strtoupper(substr($r_post['username'], 0, 1)); $r_post['ip_id'] = saveIp(); } else { $msg = ''; if ($user['email'] == $r_post['email']) { $msg = 'Email address is already exist. Your registration process is not completed. Please, try again.'; } else { if ($user['username'] == $r_post['username']) { $msg = 'Username address is already exist. Your registration process is not completed. Please, try again.'; } } $response = array('error' => $msg); } break; case '/users/login': //users login $is_login = false; $user = array(); $table_name = 'users'; $val_arr = array($r_post['email']); $log_user = executeQuery('SELECT * FROM users WHERE email = $1 or username = $1', $val_arr); if (LDAP_LOGIN_ENABLED && (empty($log_user) || !empty($log_user) && $log_user['role_id'] != 1 && $log_user['is_ldap'] == 't')) { $check_user = ldapAuthenticate($r_post['email'], $r_post['password']); if (!empty($check_user['User']) && $check_user['User']['is_username_exits'] && $check_user['User']['is_password_matched'] && isset($check_user['User']['email']) && !empty($check_user['User']['email'])) { $val_arr = array($check_user['User']['email']); $user = executeQuery('SELECT * FROM users_listing WHERE email = $1', $val_arr); if (!$user) { $r_post['password'] = getCryptHash($r_post['password']); $r_post['role_id'] = 2; // user $val_arr = array($r_post['email'], $check_user['User']['email'], $r_post['password'], strtoupper(substr($r_post['email'], 0, 1))); $result = pg_query_params($db_lnk, 'INSERT INTO ' . $table_name . ' (created, modified, role_id, username, email, password, initials, is_active, is_email_confirmed, is_ldap) VALUES (now(), now(), 2, $1, $2, $3, $4, true, true, true) RETURNING * ', $val_arr); $user = pg_fetch_assoc($result); $val_arr = array($user['id']); $user = executeQuery('SELECT * FROM users_listing WHERE id = $1', $val_arr); } } } else { if ($log_user && $log_user['is_ldap'] == 'f' && STANDARD_LOGIN_ENABLED) { $r_post['password'] = crypt($r_post['password'], $log_user['password']); $val_arr = array($r_post['email'], $r_post['password'], true); $user = executeQuery('SELECT * FROM users_listing WHERE (email = $1 or username = $1) AND password = $2 AND is_active = $3', $val_arr); } } if (!empty($user)) { if (LDAP_LOGIN_ENABLED) { $login_type_id = 1; } else { $login_type_id = 2; } $last_login_ip_id = saveIp(); $val_arr = array($login_type_id, $last_login_ip_id, $user['id']); pg_query_params($db_lnk, 'UPDATE users SET last_login_date = now(), login_type_id = $1, last_login_ip_id = $2 WHERE id = $3', $val_arr); unset($user['password']); $user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $val_arr = array($user['id'], $last_login_ip_id, $user_agent); pg_query_params($db_lnk, 'INSERT INTO user_logins (created, modified, user_id, ip_id, user_agent) VALUES (now(), now(), $1, $2, $3)', $val_arr); $role_val_arr = array($user['role_id']); $role_links = executeQuery('SELECT * FROM role_links_listing WHERE id = $1', $role_val_arr); $post_url = $_server_domain_url . str_replace('r.php', 'token.php', $_SERVER['PHP_SELF']); $post_arr = array('grant_type' => 'password', 'username' => $user['username'], 'password' => $r_post['password'], 'client_id' => OAUTH_CLIENTID, 'client_secret' => OAUTH_CLIENT_SECRET); $response = doPost($post_url, $post_arr); $response = array_merge($role_links, $response); $board_ids = array(); if (!empty($user['boards_users'])) { $boards_users = json_decode($user['boards_users'], true); foreach ($boards_users as $boards_user) { $board_ids[] = $boards_user['board_id']; } } $notify_val_arr = array($user['last_activity_id'], '{' . implode(',', $board_ids) . '}'); $notify_count = executeQuery('SELECT count(a.*) AS notify_count FROM activities a WHERE a.id > $1 AND board_id = ANY ($2) ', $notify_val_arr); $user = array_merge($user, $notify_count); $response['user'] = $user; $response['user']['organizations'] = json_decode($user['organizations'], true); } else { $response = array('error' => 'Sorry, login failed. Either your username or password are incorrect or admin deactivated your account.'); } break; case '/users/?/changepassword': $qry_val_array = array($r_resource_vars['users']); $user = executeQuery('SELECT * FROM users WHERE id = $1', $qry_val_array); if ($user) { $cry_old_pass = crypt($r_post['old_password'], $user['password']); if ($authUser['role_id'] == 2 && $user['password'] == $cry_old_pass || $authUser['role_id'] == 1) { $res_val_arr = array(getCryptHash($r_post['password']), $r_resource_vars['users']); $result = pg_query_params($db_lnk, 'UPDATE users SET (password) = ($1) WHERE id = $2', $res_val_arr); if ($authUser['role_id'] == 1) { $emailFindReplace = array('to' => $user['email'], 'mail' => 'changepassword', '##PASSWORD##' => $r_post['password']); sendMail($emailFindReplace); $response = array('success' => 'Password change successfully. Please login.'); } } else { $response = array('error' => 'Invalid old password.'); } } else { $response = array('error' => 'Unable to change password. Please try again.'); } break; case '/users/?': $is_return_vlaue = true; $profile_picture_path = 'null'; $no_error = true; if (!empty($_FILES['attachment']['name']) && $_FILES['attachment']['error'] == 0) { $mediadir = APP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'User' . DIRECTORY_SEPARATOR . $r_resource_vars['users']; $save_path = 'media' . DIRECTORY_SEPARATOR . 'User' . DIRECTORY_SEPARATOR . $r_resource_vars['users']; if (!file_exists($mediadir)) { mkdir($mediadir, 0777, true); } $file = $_FILES['attachment']; $file['name'] = preg_replace('/[^A-Za-z0-9\\-.]/', '', $file['name']); if (move_uploaded_file($file['tmp_name'], $mediadir . DIRECTORY_SEPARATOR . $file['name'])) { $profile_picture_path = $save_path . DIRECTORY_SEPARATOR . $file['name']; foreach ($thumbsizes['User'] as $key => $value) { $mediadir = APP_PATH . '/client/img/' . $key . '/User/' . $r_resource_vars['users']; $list = glob($mediadir . '.*'); @unlink($list[0]); } $authUser['profile_picture_path'] = $profile_picture_path; $response['profile_picture_path'] = $profile_picture_path; $comment = '##USER_NAME## update profile image'; $foreign_ids['user_id'] = $authUser['id']; $response['activity'] = insertActivity($authUser['id'], $comment, 'update_profile_attachment', $foreign_ids); } $qry_val_arr = array($profile_picture_path, $r_resource_vars['users']); pg_query_params($db_lnk, 'UPDATE users SET profile_picture_path = $1 WHERE id = $2', $qry_val_arr); } else { if (!empty($_POST['email'])) { $usr_val_arr = array($_POST['email']); $user = executeQuery('SELECT * FROM users WHERE email = $1', $usr_val_arr); if ($user['id'] != $r_resource_vars['users'] && $user['email'] == $_POST['email']) { $no_error = false; $msg = 'Email address is already exist. User Profile could not be updated. Please, try again.'; } } if ($no_error) { $_POST['initials'] = strtoupper($_POST['initials']); $qry_val_arr = array($_POST['full_name'], $_POST['about_me'], $_POST['initials'], $r_resource_vars['users']); $comment = '##USER_NAME## update profile.'; $foreign_ids['user_id'] = $authUser['id']; $response['activity'] = insertActivity($authUser['id'], $comment, 'update_profile', $foreign_ids); pg_query_params($db_lnk, 'UPDATE users SET full_name = $1, about_me = $2, initials = $3 WHERE id = $4', $qry_val_arr); if (!empty($_POST['email'])) { $qry_val_arr = array($_POST['email'], $r_resource_vars['users']); pg_query_params($db_lnk, 'UPDATE users SET email= $1 WHERE id = $2', $qry_val_arr); } } } if ($no_error) { $response['success'] = 'User Profile has been updated.'; } else { $response['error'] = $msg; } break; case '/settings': //settings update foreach ($r_post as $key => $value) { $qry_val_arr = array($value, trim($key)); pg_query_params($db_lnk, 'UPDATE settings SET value = $1 WHERE name = $2', $qry_val_arr); } $response = array('success' => 'Settings updated successfully.'); break; case '/boards': //boards add $is_import_board = false; if (!empty($_FILES['board_import'])) { if ($_FILES['board_import']['error'] == 0) { $get_files = file_get_contents($_FILES['board_import']['tmp_name']); $imported_board = json_decode($get_files, true); if (!empty($imported_board)) { $board = importTrelloBoard($imported_board); $response['id'] = $board['id']; } else { $response['error'] = 'Unable to import. please try again.'; } } else { $response['error'] = 'Unable to import. please try again.'; } } else { $table_name = 'boards'; $qry_val_arr = array($r_post['name']); $board = executeQuery('SELECT id, name FROM ' . $table_name . ' WHERE name = $1', $qry_val_arr); if (isset($r_post['template']) && !empty($r_post['template'])) { $lists = explode(',', $r_post['template']); } unset($r_post['template']); $sql = true; $r_post['user_id'] = !empty($authUser['id']) ? $authUser['id'] : 1; } break; case '/boards/?/boards_stars': //stars add $table_name = 'board_stars'; $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $subcriber = executeQuery('SELECT id, is_starred FROM ' . $table_name . ' WHERE board_id = $1 and user_id = $2', $qry_val_arr); if (!$subcriber) { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'INSERT INTO ' . $table_name . ' (created, modified, board_id, user_id, is_starred) VALUES (now(), now(), $1, $2, true) RETURNING id', $qry_val_arr); } else { if ($subcriber['is_starred'] == 't') { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'UPDATE ' . $table_name . ' SET is_starred = false Where board_id = $1 and user_id = $2 RETURNING id', $qry_val_arr); } else { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'UPDATE ' . $table_name . ' SET is_starred = True Where board_id = $1 and user_id = $2 RETURNING id', $qry_val_arr); } } $star = pg_fetch_assoc($result); $response['id'] = $star['id']; break; case '/boards/?/board_subscribers': //subscriber add $table_name = 'board_subscribers'; $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $subcriber = executeQuery('SELECT id, is_subscribed FROM ' . $table_name . ' WHERE board_id = $1 and user_id = $2', $qry_val_arr); if (!$subcriber) { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'INSERT INTO ' . $table_name . ' (created, modified, board_id, user_id, is_subscribed) VALUES (now(), now(), $1, $2, true) RETURNING *', $qry_val_arr); } else { if ($subcriber['is_subscribed'] == 't') { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'UPDATE ' . $table_name . ' SET is_subscribed = false Where board_id = $1 and user_id = $2 RETURNING *', $qry_val_arr); } else { $qry_val_arr = array($r_resource_vars['boards'], $authUser['id']); $result = pg_query_params($db_lnk, 'UPDATE ' . $table_name . ' SET is_subscribed = True Where board_id = $1 and user_id = $2 RETURNING *', $qry_val_arr); } } $response = pg_fetch_assoc($result); break; case '/boards/?/copy': //boards copy $table_name = 'boards'; $sql = true; $copied_board_id = $r_resource_vars['boards']; $board_visibility = $r_post['board_visibility']; if (!empty($r_post['organization_id'])) { $organization_id = $r_post['organization_id']; } $keepcards = false; if (!empty($r_post['keepCards'])) { $keepcards = true; unset($r_post['keepCards']); } $qry_val_arr = array($copied_board_id); $sresult = pg_query_params($db_lnk, 'SELECT * FROM boards WHERE id = $1', $qry_val_arr); $srow = pg_fetch_assoc($sresult); unset($srow['id']); unset($srow['created']); unset($srow['modified']); unset($srow['user_id']); unset($srow['name']); if ($srow['commenting_permissions'] === null) { $srow['commenting_permissions'] = 0; } if ($srow['voting_permissions'] === null) { $srow['voting_permissions'] = 0; } if ($srow['inivitation_permissions'] === null) { $srow['inivitation_permissions'] = 0; } $r_post = array_merge($r_post, $srow); $r_post['board_visibility'] = $board_visibility; if (!empty($organization_id)) { $r_post['organization_id'] = $organization_id; } break; case '/boards/?/custom_backgrounds': $is_return_vlaue = true; if (!empty($_FILES['attachment']) && $_FILES['attachment']['error'] == 0) { $mediadir = APP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'Board' . DIRECTORY_SEPARATOR . $r_resource_vars['boards']; $save_path = 'media' . DIRECTORY_SEPARATOR . 'Board' . DIRECTORY_SEPARATOR . $r_resource_vars['boards']; if (!file_exists($mediadir)) { mkdir($mediadir, 0777, true); } $file = $_FILES['attachment']; $file['name'] = preg_replace('/[^A-Za-z0-9\\-.]/', '', $file['name']); if (move_uploaded_file($file['tmp_name'], $mediadir . DIRECTORY_SEPARATOR . $file['name'])) { $r_post['name'] = $file['name']; foreach ($thumbsizes['Board'] as $key => $value) { $mediadir = APP_PATH . DIRECTORY_SEPARATOR . 'client' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . 'Board' . DIRECTORY_SEPARATOR . $r_resource_vars['boards']; $list = glob($mediadir . '.*'); @unlink($list[0]); } $hash = md5(SECURITYSALT . 'Board' . $r_resource_vars['boards'] . 'jpg' . 'extra_large_thumb' . SITE_NAME); $background_picture_url = $_server_domain_url . '/img/extra_large_thumb/Board/' . $r_resource_vars['boards'] . '.' . $hash . '.jpg'; $r_post['background_picture_path'] = $save_path . DIRECTORY_SEPARATOR . $file['name']; $r_post['path'] = $background_picture_url; $response['background_picture_url'] = $background_picture_url; } $qry_val_array = array($r_post['path'], $r_post['background_picture_path'], $r_resource_vars['boards']); pg_query_params($db_lnk, 'UPDATE boards SET background_picture_url = $1,background_picture_path = $2 WHERE id = $3', $qry_val_array); } break; case '/boards/?/users': $is_return_vlaue = true; $table_name = 'boards_users'; $qry_val_arr = array($r_resource_vars['boards'], $r_post['user_id']); $boards_user = executeQuery('SELECT * FROM boards_users WHERE board_id = $1 AND user_id = $2', $qry_val_arr); if (empty($boards_user)) { $sql = true; } break; case '/boards/?/lists': $table_name = 'lists'; $r_post['board_id'] = $r_resource_vars['boards']; $r_post['user_id'] = $authUser['id']; $sql = true; if (isset($r_post['clone_list_id'])) { $clone_list_id = $r_post['clone_list_id']; unset($r_post['clone_list_id']); unset($r_post['list_cards']); } break; case '/boards/?/lists/?/list_subscribers': $table_name = 'list_subscribers'; $r_post['user_id'] = $authUser['id']; $qry_val_arr = array($r_resource_vars['lists'], $r_post['user_id']); $s_result = pg_query_params($db_lnk, 'SELECT is_subscribed FROM list_subscribers WHERE list_id = $1 and user_id = $2', $qry_val_arr); $check_subscribed = pg_fetch_assoc($s_result); if (!empty($check_subscribed)) { $is_subscribed = $r_post['is_subscribed'] ? true : false; $qry_val_arr = array($is_subscribed, $r_resource_vars['lists'], $r_post['user_id']); $s_result = pg_query_params($db_lnk, 'UPDATE list_subscribers SET is_subscribed = $1 WHERE list_id = $2 and user_id = $3', $qry_val_arr); } else { $r_post['list_id'] = $r_resource_vars['lists']; $sql = true; } break; case '/boards/?/lists/?/cards': $table_name = 'cards'; $r_post['user_id'] = $authUser['id']; $qry_val_arr = array($r_post['board_id'], $r_post['list_id']); $pos_res = pg_query_params($db_lnk, 'SELECT position FROM cards WHERE board_id = $1 AND list_id = $2 ORDER BY position DESC LIMIT 1', $qry_val_arr); $position = pg_fetch_array($pos_res); if (empty($r_post['due_date'])) { unset($r_post['due_date']); } if (!empty($r_post['user_ids'])) { $r_post['members'] = explode(',', $r_post['user_ids']); } if (!isset($r_post['position'])) { $r_post['position'] = $position[0] + 1; } $sql = true; break; case '/boards/?/lists/?/cards/?/comments': $is_return_vlaue = true; $table_name = 'activities'; $sql = true; $prev_message = array(); if (isset($r_post['root']) && !empty($r_post['root'])) { $qry_val_arr = array($r_post['root']); $prev_message = executeQuery('SELECT ac.*, u,username, u.profile_picture_path, u.initials FROM activities ac LEFT JOIN users u ON ac.user_id = u.id WHERE ac.id = $1', $qry_val_arr); } $r_post['freshness_ts'] = date('Y-m-d h:i:s'); $r_post['type'] = 'add_comment'; break; case '/boards/?/lists/?/cards/?/card_subscribers': $table_name = 'card_subscribers'; $json = true; $r_post['user_id'] = $authUser['id']; unset($r_post['list_id']); unset($r_post['board_id']); $qry_val_arr = array($r_resource_vars['cards'], $r_post['user_id']); $s_result = pg_query_params($db_lnk, 'SELECT is_subscribed FROM card_subscribers WHERE card_id = $1 and user_id = $2', $qry_val_arr); $check_subscribed = pg_fetch_assoc($s_result); if (!empty($check_subscribed)) { $is_subscribed = $r_post['is_subscribed'] ? true : false; $qry_val_arr = array($is_subscribed, $r_resource_vars['cards'], $r_post['user_id']); $s_result = pg_query_params($db_lnk, 'UPDATE card_subscribers SET is_subscribed = $1 WHERE card_id = $2 and user_id = $3 RETURNING id', $qry_val_arr); $subscribe = pg_fetch_assoc($s_result); $response['id'] = $subscribe['id']; } else { $r_post['card_id'] = $r_resource_vars['cards']; $r_post['user_id'] = $r_post['user_id']; $sql = true; } break; case '/boards/?/lists/?/cards/?/card_voters': $table_name = 'card_voters'; $r_post['card_id'] = $r_resource_vars['cards']; $r_post['user_id'] = $authUser['id']; $sql = true; break; case '/boards/?/lists/?/cards/?/attachments': $is_return_vlaue = true; $table_name = 'card_attachments'; $r_post['card_id'] = $r_resource_vars['cards']; $r_post['list_id'] = $r_resource_vars['lists']; $r_post['board_id'] = $r_resource_vars['boards']; $mediadir = APP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'Card' . DIRECTORY_SEPARATOR . $r_resource_vars['cards']; $save_path = 'media' . DIRECTORY_SEPARATOR . 'Card' . DIRECTORY_SEPARATOR . $r_resource_vars['cards']; $save_path = str_replace('\\', '/', $save_path); if (!empty($_FILES['attachment']) && $_FILES['attachment']['error'] == 0) { if (!file_exists($mediadir)) { mkdir($mediadir, 0777, true); } $file = $_FILES['attachment']; if (move_uploaded_file($file['tmp_name'], $mediadir . DIRECTORY_SEPARATOR . $file['name'])) { $r_post['path'] = $save_path . '/' . $file['name']; $r_post['name'] = $file['name']; $r_post['mimetype'] = $file['type']; $qry_val_arr = array($r_post['card_id'], $r_post['name'], $r_post['path'], $r_post['list_id'], $r_post['board_id'], $r_post['mimetype']); $s_result = pg_query_params($db_lnk, 'INSERT INTO card_attachments (created, modified, card_id, name, path, list_id, board_id, mimetype) VALUES (now(), now(), $1, $2, $3, $4, $5, $6) RETURNING *', $qry_val_arr); $response['card_attachments'][] = pg_fetch_assoc($s_result); } foreach ($thumbsizes['CardAttachment'] as $key => $value) { $mediadir = APP_PATH . '/client/img/' . $key . '/CardAttachment/' . $response['card_attachments'][0]['id']; $list = glob($mediadir . '.*'); @unlink($list[0]); } $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['list_id'] = $r_resource_vars['lists']; $foreign_ids['card_id'] = $r_resource_vars['cards']; $comment = '##USER_NAME## added attachment to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_attachment', $foreign_ids, null, $response['card_attachments'][0]['id']); } else { if (!empty($_FILES['attachment']) && is_array($_FILES['attachment']['name']) && $_FILES['attachment']['error'][0] == 0) { $file = $_FILES['attachment']; for ($i = 0; $i < count($file['name']); $i++) { if (!file_exists($mediadir)) { mkdir($mediadir, 0777, true); } if (move_uploaded_file($file['tmp_name'][$i], $mediadir . DIRECTORY_SEPARATOR . $file['name'][$i])) { $r_post[$i]['path'] = $save_path . DIRECTORY_SEPARATOR . $file['name'][$i]; $r_post[$i]['name'] = $file['name'][$i]; $r_post[$i]['mimetype'] = $file['type'][$i]; $qry_val_arr = array($r_post['card_id'], $r_post[$i]['name'], $r_post[$i]['path'], $r_post['list_id'], $r_post['board_id'], $r_post[$i]['mimetype']); $s_result = pg_query_params($db_lnk, 'INSERT INTO card_attachments (created, modified, card_id, name, path, list_id, board_id, mimetype) VALUES (now(), now(), $1, $2, $3, $4, $5, $6) RETURNING *', $qry_val_arr); $response['card_attachments'][] = pg_fetch_assoc($s_result); $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['list_id'] = $r_resource_vars['lists']; $foreign_ids['card_id'] = $r_resource_vars['cards']; $comment = '##USER_NAME## added attachment to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_attachment', $foreign_ids, null, $response['card_attachments'][$i]['id']); foreach ($thumbsizes['CardAttachment'] as $key => $value) { $mediadir = APP_PATH . '/client/img/' . $key . '/CardAttachment/' . $response['card_attachments'][$i]['id']; $list = glob($mediadir . '.*'); @unlink($list[0]); } } } } else { if (isset($r_post['image_link']) && !empty($r_post['image_link'])) { $filename = curlExecute($r_post['image_link'], 'get', $mediadir, 'image'); $sql = true; unset($r_post['image_link']); $r_post['path'] = $save_path . '/' . $filename; $r_post['name'] = $filename; } } } break; case '/boards/?/lists/?/cards/?/labels': $is_return_vlaue = true; $table_name = 'cards_labels'; $r_post['card_id'] = $r_resource_vars['cards']; $r_post['list_id'] = $r_resource_vars['lists']; $r_post['board_id'] = $r_resource_vars['boards']; $qry_val_arr = array($r_resource_vars['cards']); $delete_labels = pg_query_params($db_lnk, 'DELETE FROM ' . $table_name . ' WHERE card_id = $1', $qry_val_arr); $delete_labels_count = pg_affected_rows($delete_labels); if (!empty($r_post['name'])) { $label_names = explode(',', $r_post['name']); unset($r_post['name']); foreach ($label_names as $label_name) { $qry_val_arr = array($label_name); $s_result = pg_query_params($db_lnk, 'SELECT id FROM labels WHERE name = $1', $qry_val_arr); $label = pg_fetch_assoc($s_result); if (empty($label)) { $qry_val_arr = array($label_name); $s_result = pg_query_params($db_lnk, 'INSERT INTO labels (created, modified, name) VALUES (now(), now(), $1) RETURNING id', $qry_val_arr); $label = pg_fetch_assoc($s_result); } $r_post['label_id'] = $label['id']; $qry_val_arr = array($r_post['card_id'], $r_post['label_id'], $r_post['board_id'], $r_post['list_id']); pg_query_params($db_lnk, 'INSERT INTO ' . $table_name . ' (created, modified, card_id, label_id, board_id, list_id) VALUES (now(), now(), $1, $2, $3, $4) RETURNING *', $qry_val_arr); } $qry_val_arr = array($r_post['card_id']); $s_result = pg_query_params($db_lnk, 'SELECT * FROM cards_labels_listing WHERE card_id = $1', $qry_val_arr); $cards_labels = pg_fetch_all($s_result); $response['cards_labels'] = $cards_labels; $comment = '##USER_NAME## added label(s) to this card ##CARD_LINK## - ##LABEL_NAME##'; } else { $response['cards_labels'] = array(); $comment = '##USER_NAME## removed label(s) in this card ##CARD_LINK## - ##LABEL_NAME##'; } $foreign_ids['board_id'] = $r_post['board_id']; $foreign_ids['list_id'] = $r_post['list_id']; $foreign_ids['card_id'] = $r_post['card_id']; if (!empty($delete_labels_count)) { $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_label', $foreign_ids, null, $r_post['label_id']); } break; case '/boards/?/lists/?/cards/?/checklists': $sql = true; $table_name = 'checklists'; $r_post['user_id'] = $authUser['id']; $r_post['card_id'] = $r_resource_vars['cards']; if (isset($r_post['checklist_id'])) { $checklist_id = $r_post['checklist_id']; unset($r_post['checklist_id']); } break; case '/boards/?/lists/?/cards/?/checklists/?/items': $table_name = 'checklist_items'; $is_return_vlaue = true; $r_post['user_id'] = $authUser['id']; $r_post['card_id'] = $r_resource_vars['cards']; $r_post['checklist_id'] = $r_resource_vars['checklists']; unset($r_post['created']); unset($r_post['modified']); unset($r_post['is_offline']); unset($r_post['list_id']); unset($r_post['board_id']); $names = explode("\n", $r_post['name']); foreach ($names as $name) { $r_post['name'] = trim($name); if (!empty($r_post['name'])) { $qry_val_arr = array($r_post['checklist_id']); $position = executeQuery('SELECT max(position) as position FROM checklist_items WHERE checklist_id = $1', $qry_val_arr); $r_post['position'] = $position['position']; if (empty($r_post['position'])) { $r_post['position'] = 0; } $r_post['position'] += 1; $result = pg_execute_insert($table_name, $r_post); $item = pg_fetch_assoc($result); $response[$table_name][] = $item; $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['list_id'] = $r_resource_vars['lists']; $foreign_ids['card_id'] = $r_post['card_id']; $comment = '##USER_NAME## added item ##CHECKLIST_ITEM_NAME## in checklist ##CHECKLIST_ITEM_PARENT_NAME## of card ##CARD_LINK##'; $response['activities'][] = insertActivity($authUser['id'], $comment, 'add_checklist_item', $foreign_ids, '', $item['id']); } } break; case '/boards/?/lists/?/cards/?/checklists/?/items/?/convert_to_card': $is_return_vlaue = true; $table_name = 'cards'; $qry_val_arr = array($r_resource_vars['items']); $result = pg_query_params($db_lnk, 'SELECT name FROM checklist_items WHERE id = $1', $qry_val_arr); $row = pg_fetch_assoc($result); $r_post['board_id'] = $r_resource_vars['boards']; $r_post['list_id'] = $r_resource_vars['lists']; $r_post['name'] = $row['name']; $qry_val_arr = array($r_post['list_id']); $sresult = pg_query_params($db_lnk, 'SELECT max(position) as position FROM cards WHERE list_id = $1', $qry_val_arr); $srow = pg_fetch_assoc($sresult); $r_post['position'] = $srow['position']; $r_post['user_id'] = $authUser['id']; $sql = true; break; case '/boards/?/lists/?/cards/?/users/?': $is_return_vlaue = true; $table_name = 'cards_users'; unset($r_post['board_id']); unset($r_post['list_id']); unset($r_post['is_offline']); unset($r_post['profile_picture_path']); unset($r_post['username']); unset($r_post['initials']); $qry_val_arr = array($r_resource_vars['cards'], $r_resource_vars['users']); $check_already_added = executeQuery('SELECT * FROM cards_users WHERE card_id = $1 AND user_id = $2', $qry_val_arr); if (!empty($check_already_added)) { $response['id'] = $check_already_added['id']; $response['cards_users'] = $check_already_added; } else { $sql = true; } break; case '/boards/?/lists/?/cards/?/copy': $is_return_vlaue = true; $r_post['user_id'] = $authUser['id']; $table_name = 'cards'; $is_keep_attachment = $is_keep_user = $is_keep_label = $is_keep_activity = $is_keep_checklist = 0; if (isset($r_post['keep_attachments'])) { $is_keep_attachment = $r_post['keep_attachments']; unset($r_post['keep_attachments']); } if (isset($r_post['keep_activities'])) { $is_keep_activity = $r_post['keep_activities']; unset($r_post['keep_activities']); } if (isset($r_post['keep_labels'])) { $is_keep_label = $r_post['keep_labels']; unset($r_post['keep_labels']); } if (isset($r_post['keep_users'])) { $is_keep_user = $r_post['keep_users']; unset($r_post['keep_users']); } if (isset($r_post['keep_checklists'])) { $is_keep_checklist = $r_post['keep_checklists']; unset($r_post['keep_checklists']); } $copied_card_id = $r_resource_vars['cards']; unset($r_post['copied_card_id']); $qry_val_arr = array($copied_card_id); $sresult = pg_query_params($db_lnk, 'SELECT * FROM cards WHERE id = $1', $qry_val_arr); $srow = pg_fetch_assoc($sresult); unset($srow['id']); $card_name = $r_post['name']; $r_post = array_merge($srow, $r_post); $r_post['name'] = $card_name; $list_card_objs = pg_query_params($db_lnk, 'SELECT * FROM cards_listing WHERE list_id = $1 AND is_archived = $2 ORDER BY position ASC', array($r_post['list_id'], 'false')); $list_cards = array(); $h = 1; while ($card = pg_fetch_assoc($list_card_objs)) { $list_cards[$h] = $card; $h++; } if (isset($list_cards[$r_post['position']]) && isset($list_cards[$r_post['position'] - 1])) { $r_post['position'] = ($list_cards[$r_post['position']]['position'] + $list_cards[$r_post['position'] - 1]['position']) / 2; } else { if (!isset($list_cards[$r_post['position']]) && isset($list_cards[$r_post['position'] - 1])) { $r_post['position'] = $list_cards[$r_post['position'] - 1]['position'] + 1; } else { if (isset($list_cards[$r_post['position']]) && !isset($list_cards[$r_post['position'] - 1])) { $r_post['position'] = $list_cards[$r_post['position']]['position'] / 2; } else { if (!isset($list_cards[$r_post['position']]) && !isset($list_cards[$r_post['position'] - 1])) { $r_post['position'] = 1; } } } } $sql = true; break; case '/organizations/?/users/?': //organization users add $table_name = 'organizations_users'; $sql = true; $is_return_vlaue = true; break; case '/organizations': //organizations add $sql = true; $table_name = 'organizations'; $r_post['user_id'] = !empty($authUser['id']) ? $authUser['id'] : 1; $r_post['organization_visibility'] = 2; break; case '/organizations/?/upload_logo': // organizations logo upload $sql = false; $json = true; $organization_id = $r_resource_vars['organizations']; if (!empty($_FILES['attachment']) && $_FILES['attachment']['error'] == 0) { $mediadir = APP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'Organization' . DIRECTORY_SEPARATOR . $r_resource_vars['organizations']; $save_path = 'media' . DIRECTORY_SEPARATOR . 'Organization' . DIRECTORY_SEPARATOR . $r_resource_vars['organizations']; if (!file_exists($mediadir)) { mkdir($mediadir, 0777, true); } $file = $_FILES['attachment']; $file['name'] = preg_replace('/[^A-Za-z0-9\\-.]/', '', $file['name']); if (move_uploaded_file($file['tmp_name'], $mediadir . DIRECTORY_SEPARATOR . $file['name'])) { $logo_url = $save_path . DIRECTORY_SEPARATOR . $file['name']; foreach ($thumbsizes['Organization'] as $key => $value) { $list = glob(APP_PATH . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . 'Organization' . DIRECTORY_SEPARATOR . $r_resource_vars['organizations'] . '.*'); @unlink($list[0]); } foreach ($thumbsizes['Organization'] as $key => $value) { $mediadir = APP_PATH . '/client/img/' . $key . '/Organization/' . $r_resource_vars['organizations']; $list = glob($mediadir . '.*'); @unlink($list[0]); } $qry_val_arr = array($logo_url, $r_resource_vars['organizations']); pg_query_params($db_lnk, 'UPDATE organizations SET logo_url = $1 WHERE id = $2', $qry_val_arr); $response['logo_url'] = $logo_url; $foreign_ids['organization_id'] = $r_resource_vars['organizations']; $comment = (!empty($authUser['full_name']) ? $authUser['full_name'] : $authUser['username']) . ' added attachment to this organization ##ORGANIZATION_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_organization_attachment', $foreign_ids); } } break; case '/acl_links': $table_name = 'acl_links_roles'; $qry_val_arr = array($r_post['acl_link_id'], $r_post['role_id']); $acl = executeQuery('SELECT * FROM ' . $table_name . ' WHERE acl_link_id = $1 AND role_id = $2', $qry_val_arr); if ($acl) { $qry_val_arr = array($r_post['acl_link_id'], $r_post['role_id']); pg_query_params($db_lnk, 'DELETE FROM ' . $table_name . ' WHERE acl_link_id = $1 AND role_id = $2', $qry_val_arr); } else { $qry_val_arr = array($r_post['acl_link_id'], $r_post['role_id']); pg_query_params($db_lnk, 'INSERT INTO ' . $table_name . ' (created, modified, acl_link_id, role_id) VALUES(now(), now(), $1, $2)', $qry_val_arr); } break; default: header($_SERVER['SERVER_PROTOCOL'] . ' 501 Not Implemented', true, 501); break; } if (!empty($sql)) { $post = getbindValues($table_name, $r_post); $result = pg_execute_insert($table_name, $post); if ($result) { $row = pg_fetch_assoc($result); $response['id'] = $row['id']; if ($is_return_vlaue) { $response[$table_name] = $row; } if (!empty($uuid)) { $response['uuid'] = $uuid; } if ($r_resource_cmd == '/users/register') { $emailFindReplace['##USERNAME##'] = $r_post['username']; $emailFindReplace['##ACTIVATION_URL##'] = 'http://' . $_SERVER['HTTP_HOST'] . '/#/users/activation/' . $row['id'] . '/' . md5($r_post['username']); $emailFindReplace['to'] = $r_post['email']; $emailFindReplace['mail'] = 'activation'; sendMail($emailFindReplace); } else { if ($r_resource_cmd == '/boards') { if (!$is_import_board) { $foreign_id['board_id'] = $response['id']; $comment = '##USER_NAME## created board'; $qry_val_arr = array($row['id'], $r_post['user_id']); $response['activity'] = insertActivity($authUser['id'], $comment, 'add_board', $foreign_id); $result = pg_query_params($db_lnk, 'INSERT INTO boards_users (created, modified, board_id , user_id, is_admin) VALUES (now(), now(), $1, $2, true)', $qry_val_arr); if (isset($lists) && !empty($lists)) { $position = 1; $total_list = count($lists); $s_sql = 'INSERT INTO lists (created, modified, board_id, name, user_id, position) VALUES'; foreach ($lists as $list) { $qry_val_arr = array($response['id'], $list, $authUser['id'], $position); $s_sql = 'INSERT INTO lists (created, modified, board_id, name, user_id, position) VALUES'; $s_sql .= '(now(), now(), $1, $2, $3, $4)'; pg_query_params($db_lnk, $s_sql, $qry_val_arr); $position++; } } $qry_val_arr = array($row['id']); $response['simple_board'] = executeQuery('SELECT row_to_json(d) FROM (SELECT * FROM simple_board_listing sbl WHERE id = $1 ORDER BY id ASC) as d', $qry_val_arr); $response['simple_board'] = json_decode($response['simple_board']['row_to_json'], true); } } else { if ($r_resource_cmd == '/organizations') { $qry_val_arr = array($row['id'], $r_post['user_id']); $result = pg_query_params($db_lnk, 'INSERT INTO organizations_users (created, modified, organization_id , user_id, is_admin) VALUES (now(), now(), $1, $2, true)', $qry_val_arr); $foreign_id['organization_id'] = $row['id']; $comment = '##USER_NAME## created organization "##ORGANIZATION_LINK##"'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_organization', $foreign_id); } else { if ($r_resource_cmd == '/boards/?/lists') { $foreign_ids['board_id'] = $r_post['board_id']; $foreign_ids['list_id'] = $response['id']; $comment = '##USER_NAME## added list "' . $r_post['name'] . '".'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_list', $foreign_ids); $copy_checklists = array(); $copy_checklists_items = array(); if (!empty($clone_list_id)) { $qry_val_arr = array($clone_list_id); $s_result = pg_query_params($db_lnk, 'SELECT name, board_id, position FROM lists WHERE id = $1', $qry_val_arr); $previous_list = pg_fetch_assoc($s_result); $new_list_id = $response['id']; // Copy cards $card_fields = 'board_id, name, description, position, due_date, is_archived, attachment_count, checklist_count, checklist_item_count, checklist_item_completed_count, label_count, cards_user_count, cards_subscriber_count, card_voter_count, activity_count, user_id, comment_count'; $card_fields = 'list_id, ' . $card_fields; $qry_val_arr = array($clone_list_id); $cards = pg_query_params($db_lnk, 'SELECT id, ' . $card_fields . ' FROM cards WHERE list_id = $1 ORDER BY id', $qry_val_arr); if (pg_num_rows($cards)) { copyCards($card_fields, $cards, $new_list_id, $post['name'], $foreign_ids['board_id']); } } $qry_val_arr = array($foreign_ids['list_id']); $s_result = pg_query_params($db_lnk, 'SELECT * FROM lists_listing WHERE id = $1', $qry_val_arr); $list = pg_fetch_assoc($s_result); $response['list'] = $list; $qry_val_arr = array($foreign_ids['list_id']); $attachments = pg_query_params($db_lnk, 'SELECT * FROM card_attachments WHERE list_id = $1', $qry_val_arr); while ($attachment = pg_fetch_assoc($attachments)) { $response['list']['attachments'][] = $attachment; } $qry_val_arr = array($foreign_ids['list_id']); $activities = pg_query_params($db_lnk, 'SELECT * FROM activities_listing WHERE list_id = $1', $qry_val_arr); while ($activity = pg_fetch_assoc($activities)) { $response['list']['activities'][] = $activity; } $response['list']['checklists'] = $copy_checklists; $response['list']['checklists_items'] = $copy_checklists_items; $qry_val_arr = array($foreign_ids['list_id']); $labels = pg_query_params($db_lnk, 'SELECT * FROM cards_labels_listing WHERE list_id = $1', $qry_val_arr); while ($label = pg_fetch_assoc($labels)) { $response['list']['labels'][] = $label; } $response['list']['cards'] = json_decode($response['list']['cards'], true); $response['list']['lists_subscribers'] = json_decode($response['list']['lists_subscribers'], true); } else { if ($r_resource_cmd == '/boards/?/lists/?/cards' || $r_resource_cmd == '/boards/?/lists/?/cards/?/checklists/?/items/?/convert_to_card') { $qry_val_arr = array($r_post['list_id']); $s_result = pg_query_params($db_lnk, 'SELECT name FROM lists WHERE id = $1', $qry_val_arr); $list = pg_fetch_assoc($s_result); $foreign_ids['board_id'] = $r_post['board_id']; $foreign_ids['card_id'] = $response['id']; $foreign_ids['list_id'] = $r_post['list_id']; $comment = '##USER_NAME## added card ##CARD_LINK## to list "' . $list['name'] . '".'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card', $foreign_ids); if (!empty($r_post['members'])) { $s_usql = ''; foreach ($r_post['members'] as $member) { $s_usql = 'INSERT INTO cards_users (created, modified, card_id, user_id) VALUES(now(), now(), ' . $response['id'] . ', ' . $member . ') RETURNING id'; $s_result = pg_query_params($db_lnk, $s_usql, array()); $card_user = pg_fetch_assoc($s_result); $qry_val_arr = array($member); $_user = executeQuery('SELECT username FROM users WHERE id = $1', $qry_val_arr); $comment = '##USER_NAME## added "' . $_user['username'] . '" as member to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_user', $foreign_ids, '', $card_user['id']); } } $qry_val_arr = array($response['id']); $cards_users = pg_query_params($db_lnk, 'SELECT * FROM cards_users_listing WHERE card_id = $1', $qry_val_arr); while ($cards_user = pg_fetch_assoc($cards_users)) { $response['cards_users'][] = $cards_user; } if (!empty($r_post['labels'])) { $r_post['card_labels'] = $r_post['labels']; } if (!empty($r_post['card_labels'])) { $label_names = explode(',', $r_post['card_labels']); foreach ($label_names as $label_name) { $qry_val_arr = array($label_name); $s_result = pg_query_params($db_lnk, 'SELECT id FROM labels WHERE name = $1', $qry_val_arr); $label = pg_fetch_assoc($s_result); if (empty($label)) { $qry_val_arr = array($label_name); $s_result = pg_query_params($db_lnk, $s_sql = 'INSERT INTO labels (created, modified, name) VALUES (now(), now(), $1) RETURNING id', $qry_val_arr); $label = pg_fetch_assoc($s_result); } $r_post['label_id'] = $label['id']; $r_post['card_id'] = $row['id']; $r_post['list_id'] = $row['list_id']; $r_post['board_id'] = $row['board_id']; $qry_val_arr = array($r_post['card_id'], $r_post['label_id'], $r_post['board_id'], $r_post['list_id']); pg_query_params($db_lnk, 'INSERT INTO cards_labels (created, modified, card_id, label_id, board_id, list_id) VALUES (now(), now(), $1, $2, $3, $4) RETURNING *', $qry_val_arr); } $comment = '##USER_NAME## added label(s) to this card ##CARD_LINK## - ##LABEL_NAME##'; insertActivity($authUser['id'], $comment, 'add_card_label', $foreign_ids); } $qry_val_arr = array($response['id']); $cards_labels = pg_query_params($db_lnk, 'SELECT * FROM cards_labels_listing WHERE card_id = $1', $qry_val_arr); while ($cards_label = pg_fetch_assoc($cards_labels)) { $response['cards_labels'][] = $cards_label; } if (!empty($clone_card_id)) { $qry_val_arr = array($response['id'], $clone_card_id); pg_query_params($db_lnk, 'INSERT INTO card_attachments (created, modified, card_id, name, path, mimetype) SELECT created, modified, $1, name, path, mimetype FROM card_attachments WHERE card_id = $2', $qry_val_arr); $qry_val_arr = array($clone_card_id); $s_result = pg_query_params($db_lnk, 'SELECT name, list_id, board_id, position FROM lists WHERE id = $1', $qry_val_arr); $previous_value = pg_fetch_assoc($s_result); $comment = '##USER_NAME## copied card "' . $r_post['name'] . '". from "' . $previous_value['name'] . '"'; $response['activity'] = insertActivity($authUser['id'], $comment, 'copy_card', $foreign_id); } } else { if ($r_resource_cmd == '/boards/?/copy') { $new_board_id = $row['id']; //Copy board users $boards_user_fields = 'user_id, is_admin'; $qry_val_arr = array($r_resource_vars['boards']); $boards_users = pg_query_params($db_lnk, 'SELECT id, ' . $boards_user_fields . ' FROM boards_users WHERE board_id = $1', $qry_val_arr); if ($boards_users && pg_num_rows($boards_users)) { $boards_user_fields = 'created, modified, board_id, ' . $boards_user_fields; while ($boards_user = pg_fetch_object($boards_users)) { $boards_user_values = array(); array_push($boards_user_values, 'now()', 'now()', $new_board_id); foreach ($boards_user as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($boards_user_values, 'false'); } else { if ($value === null) { array_push($boards_user_values, null); } else { array_push($boards_user_values, $value); } } } } $boards_user_val = ''; for ($i = 1, $len = count($boards_user_values); $i <= $len; $i++) { $boards_user_val .= '$' . $i; $boards_user_val .= $i != $len ? ', ' : ''; } $boards_user_result = pg_query_params($db_lnk, 'INSERT INTO boards_users (' . $boards_user_fields . ') VALUES (' . $boards_user_val . ') RETURNING id', $boards_user_values); } } //Copy board subscribers $boards_subscriber_fields = 'user_id, is_subscribed'; $qry_val_arr = array($r_resource_vars['boards']); $boards_subscribers = pg_query_params($db_lnk, 'SELECT id, ' . $boards_subscriber_fields . ' FROM board_subscribers WHERE board_id = $1', $qry_val_arr); if ($boards_subscribers && pg_num_rows($boards_subscribers)) { $boards_subscriber_fields = 'created, modified, board_id, ' . $boards_subscriber_fields; while ($boards_subscriber = pg_fetch_object($boards_subscribers)) { $boards_subscriber_values = array(); array_push($boards_subscriber_values, 'now()', 'now()', $new_board_id); foreach ($boards_subscriber as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($boards_subscriber_values, 'false'); } else { if ($value === null) { array_push($boards_subscriber_values, null); } else { array_push($boards_subscriber_values, $value); } } } } $boards_subscriber_val = ''; for ($i = 1, $len = count($boards_subscriber_values); $i <= $len; $i++) { $boards_subscriber_val .= '$' . $i; $boards_subscriber_val .= $i != $len ? ', ' : ''; } $boards_subscriber_result = pg_query_params($db_lnk, 'INSERT INTO board_subscribers (' . $boards_subscriber_fields . ') VALUES (' . $boards_subscriber_val . ') RETURNING id', $boards_subscriber_values); } } //Copy board star $boards_star_fields = 'user_id, is_starred'; $qry_val_arr = array($r_resource_vars['boards']); $boards_stars = pg_query_params($db_lnk, 'SELECT id, ' . $boards_star_fields . ' FROM board_stars WHERE board_id = $1', $qry_val_arr); if ($boards_stars && pg_num_rows($boards_stars)) { $boards_star_fields = 'created, modified, board_id, ' . $boards_star_fields; while ($boards_star = pg_fetch_object($boards_stars)) { $boards_star_values = array(); array_push($boards_star_values, 'now()', 'now()', $new_board_id); foreach ($boards_star as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($boards_star_values, 'false'); } else { if ($value === null) { array_push($boards_star_values, null); } else { array_push($boards_star_values, $value); } } } } $boards_star_val = ''; for ($i = 1, $len = count($boards_star_values); $i <= $len; $i++) { $boards_star_val .= '$' . $i; $boards_star_val .= $i != $len ? ', ' : ''; } $boards_star_result = pg_query_params($db_lnk, 'INSERT INTO board_stars (' . $boards_star_fields . ') VALUES (' . $boards_star_val . ') RETURNING id', $boards_star_values); } } if ($keepcards) { $qry_val_arr = array($r_resource_vars['boards']); $lists = pg_query_params($db_lnk, 'SELECT id, name, position, is_archived, card_count, lists_subscriber_count FROM lists WHERE board_id = $1', $qry_val_arr); } else { $qry_val_arr = array($r_resource_vars['boards']); $lists = pg_query_params($db_lnk, 'SELECT id, name, position, is_archived, lists_subscriber_count FROM lists WHERE board_id = $1', $qry_val_arr); } if ($lists) { // Copy lists while ($list = pg_fetch_object($lists)) { $list_id = $list->id; $list_fields = 'created, modified, board_id, user_id'; $list_values = array(); array_push($list_values, 'now()', 'now()', $new_board_id, $authUser['id']); foreach ($list as $key => $value) { if ($key != 'id') { $list_fields .= ', ' . $key; if ($value === false) { array_push($list_values, 'false'); } else { array_push($list_values, $value); } } } $list_val = ''; for ($i = 1, $len = count($list_values); $i <= $len; $i++) { $list_val .= '$' . $i; $list_val .= $i != $len ? ', ' : ''; } $lists_result = pg_query_params($db_lnk, 'INSERT INTO lists (' . $list_fields . ') VALUES (' . $list_val . ') RETURNING id', $list_values); if ($lists_result) { $list_result = pg_fetch_assoc($lists_result); $new_list_id = $list_result['id']; //Copy list subscribers $lists_subscriber_fields = 'user_id, is_subscribed'; $qry_val_arr = array($list_id); $lists_subscribers = pg_query_params($db_lnk, 'SELECT id, ' . $lists_subscriber_fields . ' FROM list_subscribers WHERE list_id = $1', $qry_val_arr); if ($lists_subscribers && pg_num_rows($lists_subscribers)) { $lists_subscriber_fields = 'created, modified, list_id, ' . $lists_subscriber_fields; while ($lists_subscriber = pg_fetch_object($lists_subscribers)) { $lists_subscriber_values = array(); array_push($lists_subscriber_values, 'now()', 'now()', $new_list_id); foreach ($lists_subscriber as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($lists_subscriber_values, 'false'); } else { if ($value === null) { array_push($lists_subscriber_values, null); } else { array_push($lists_subscriber_values, $value); } } } } $lists_subscriber_val = ''; for ($i = 1, $len = count($lists_subscriber_values); $i <= $len; $i++) { $lists_subscriber_val .= '$' . $i; $lists_subscriber_val .= $i != $len ? ', ' : ''; } $lists_subscriber_result = pg_query_params($db_lnk, 'INSERT INTO list_subscribers (' . $lists_subscriber_fields . ') VALUES (' . $lists_subscriber_val . ') RETURNING id', $lists_subscriber_values); } } // Copy cards $card_fields = 'name, description, due_date, position, is_archived, attachment_count, checklist_count, checklist_item_count, checklist_item_completed_count, label_count, cards_user_count, cards_subscriber_count, card_voter_count, activity_count, user_id, comment_count'; if ($keepcards) { $qry_val_arr = array($list_id); $cards = pg_query_params($db_lnk, 'SELECT id, ' . $card_fields . ' FROM cards WHERE list_id = $1', $qry_val_arr); } if ($keepcards && pg_num_rows($cards)) { $card_fields = 'created, modified, board_id, list_id, ' . $card_fields; while ($card = pg_fetch_object($cards)) { $card_id = $card->id; $card_values = array(); array_push($card_values, 'now()', 'now()', $new_board_id, $new_list_id); foreach ($card as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($card_values, 'false'); } else { if ($value === null) { array_push($card_values, null); } else { array_push($card_values, $value); } } } } $card_val = ''; for ($i = 1, $len = count($card_values); $i <= $len; $i++) { $card_val .= '$' . $i; $card_val .= $i != $len ? ', ' : ''; } $card_result = pg_query_params($db_lnk, 'INSERT INTO cards (' . $card_fields . ') VALUES (' . $card_val . ') RETURNING id', $card_values); if ($card_result) { $card_result = pg_fetch_assoc($card_result); $new_card_id = $card_result['id']; //Copy card attachments $attachment_fields = 'name, path, mimetype'; $qry_val_arr = array($card_id); $attachments = pg_query_params($db_lnk, 'SELECT id, ' . $attachment_fields . ' FROM card_attachments WHERE card_id = $1', $qry_val_arr); if ($attachments && pg_num_rows($attachments)) { $attachment_fields = 'created, modified, board_id, list_id, card_id, ' . $attachment_fields; while ($attachment = pg_fetch_object($attachments)) { $attachment_values = array(); array_push($attachment_values, 'now()', 'now()', $new_board_id, $new_list_id, $new_card_id); foreach ($attachment as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($attachment_values, 'false'); } else { if ($value === null) { array_push($attachment_values, null); } else { array_push($attachment_values, $value); } } } } $attachment_val = ''; for ($i = 1, $len = count($attachment_values); $i <= $len; $i++) { $attachment_val .= '$' . $i; $attachment_val .= $i != $len ? ', ' : ''; } $card_result = pg_query_params($db_lnk, 'INSERT INTO card_attachments (' . $attachment_fields . ') VALUES (' . $attachment_val . ') RETURNING id', $attachment_values); } } //Copy checklists $checklist_fields = 'user_id, name, checklist_item_count, checklist_item_completed_count, position'; $qry_val_arr = array($card_id); $checklists = pg_query_params($db_lnk, 'SELECT id, ' . $checklist_fields . ' FROM checklists WHERE card_id = $1', $qry_val_arr); if ($checklists && pg_num_rows($checklists)) { $checklist_fields = 'created, modified, card_id, ' . $checklist_fields; while ($checklist = pg_fetch_object($checklists)) { $checklist_values = array(); array_push($checklist_values, 'now()', 'now()', $new_card_id); $checklist_id = $checklist->id; foreach ($checklist as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($checklist_values, 'false'); } else { if ($value === null) { array_push($checklist_values, null); } else { array_push($checklist_values, $value); } } } } $checklist_val = ''; for ($i = 1, $len = count($checklist_values); $i <= $len; $i++) { $checklist_val .= '$' . $i; $checklist_val .= $i != $len ? ', ' : ''; } $checklist_result = pg_query_params($db_lnk, 'INSERT INTO checklists (' . $checklist_fields . ') VALUES (' . $checklist_val . ') RETURNING id', $checklist_values); if ($checklist_result) { $checklist_result = pg_fetch_assoc($checklist_result); $new_checklist_id = $checklist_result['id']; //Copy checklist items $checklist_item_fields = 'user_id, name, position'; $qry_val_array = array($checklist_id); $checklist_items = pg_query_params($db_lnk, 'SELECT id, ' . $checklist_item_fields . ' FROM checklist_items WHERE checklist_id = $1', $qry_val_array); if ($checklist_items && pg_num_rows($checklist_items)) { $checklist_item_fields = 'created, modified, card_id, checklist_id, ' . $checklist_item_fields; while ($checklist_item = pg_fetch_object($checklist_items)) { $checklist_item_values = array(); array_push($checklist_item_values, 'now()', 'now()', $new_card_id, $new_checklist_id); foreach ($checklist_item as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($checklist_item_values, 'false'); } else { if ($value === null) { array_push($checklist_item_values, null); } else { array_push($checklist_item_values, $value); } } } } $checklist_item_val = ''; for ($i = 1, $len = count($checklist_item_values); $i <= $len; $i++) { $checklist_item_val .= '$' . $i; $checklist_item_val .= $i != $len ? ', ' : ''; } $checklist_item_result = pg_query_params($db_lnk, 'INSERT INTO checklist_items (' . $checklist_item_fields . ') VALUES (' . $checklist_item_val . ') RETURNING id', $checklist_item_values); } } } } } //Copy card voters $card_voter_fields = 'user_id'; $qry_val_arr = array($card_id); $card_voters = pg_query_params($db_lnk, 'SELECT id, ' . $card_voter_fields . ' FROM card_voters WHERE card_id = $1', $qry_val_arr); if ($card_voters && pg_num_rows($card_voters)) { $card_voter_fields = 'created, modified, card_id, ' . $card_voter_fields; while ($card_voter = pg_fetch_object($card_voters)) { $card_voter_values = array(); array_push($card_voter_values, 'now()', 'now()', $new_card_id); foreach ($card_voter as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($card_voter_values, 'false'); } else { if ($value === null) { array_push($card_voter_values, null); } else { array_push($card_voter_values, $value); } } } } $card_voter_val = ''; for ($i = 1, $len = count($card_voter_values); $i <= $len; $i++) { $card_voter_val .= '$' . $i; $card_voter_val .= $i != $len ? ', ' : ''; } $card_voter_result = pg_query_params($db_lnk, 'INSERT INTO card_voters (' . $card_voter_fields . ') VALUES (' . $card_voter_val . ') RETURNING id', $card_voter_values); } } //Copy card labels $cards_label_fields = 'label_id'; $qry_val_arr = array($card_id); $cards_labels = pg_query_params($db_lnk, 'SELECT id, ' . $cards_label_fields . ' FROM cards_labels WHERE card_id = $1', $qry_val_arr); if ($cards_labels && pg_num_rows($cards_labels)) { $cards_label_fields = 'created, modified, board_id, list_id, card_id, ' . $cards_label_fields; while ($cards_label = pg_fetch_object($cards_labels)) { $cards_label_values = array(); array_push($cards_label_values, 'now()', 'now()', $new_board_id, $new_list_id, $new_card_id); foreach ($cards_label as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($cards_label_values, 'false'); } else { if ($value === null) { array_push($cards_label_values, null); } else { array_push($cards_label_values, $value); } } } } $cards_label_val = ''; for ($i = 1, $len = count($cards_label_values); $i <= $len; $i++) { $cards_label_val .= '$' . $i; $cards_label_val .= $i != $len ? ', ' : ''; } $cards_label_result = pg_query_params($db_lnk, 'INSERT INTO cards_labels (' . $cards_label_fields . ') VALUES (' . $cards_label_val . ') RETURNING id', $cards_label_values); } } //Copy card subscribers $cards_subscriber_fields = 'user_id, is_subscribed'; $qry_val_arr = array($card_id); $cards_subscribers = pg_query_params($db_lnk, 'SELECT id, ' . $cards_subscriber_fields . ' FROM card_subscribers WHERE card_id = $1', $qry_val_arr); if ($cards_subscribers && pg_num_rows($cards_subscribers)) { $cards_subscriber_fields = 'created, modified, card_id, ' . $cards_subscriber_fields; while ($cards_subscriber = pg_fetch_object($cards_subscribers)) { $cards_subscriber_values = array(); array_push($cards_subscriber_values, 'now()', 'now()', $new_card_id); foreach ($cards_subscriber as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($cards_subscriber_values, 'false'); } else { if ($value === null) { array_push($cards_subscriber_values, null); } else { array_push($cards_subscriber_values, $value); } } } } $cards_subscriber_val = ''; for ($i = 1, $len = count($cards_subscriber_values); $i <= $len; $i++) { $cards_subscriber_val .= '$' . $i; $cards_subscriber_val .= $i != $len ? ', ' : ''; } $cards_subscriber_result = pg_query_params($db_lnk, 'INSERT INTO card_subscribers (' . $cards_subscriber_fields . ') VALUES (' . $cards_subscriber_val . ') RETURNING id', $cards_subscriber_values); } } //Copy card users $cards_user_fields = 'user_id'; $qry_val_arr = array($card_id); $cards_users = pg_query_params($db_lnk, 'SELECT id, ' . $cards_user_fields . ' FROM cards_users WHERE card_id = $1', $qry_val_arr); if ($cards_users && pg_num_rows($cards_users)) { $cards_user_fields = 'created, modified, card_id, ' . $cards_user_fields; while ($cards_user = pg_fetch_object($cards_users)) { $cards_user_values = array(); array_push($cards_user_values, 'now()', 'now()', $new_card_id); foreach ($cards_user as $key => $value) { if ($key != 'id') { if ($value === false) { array_push($cards_user_values, 'false'); } else { if ($value === null) { array_push($cards_user_values, null); } else { array_push($cards_user_values, $value); } } } } $cards_user_val = ''; for ($i = 1, $len = count($cards_user_values); $i <= $len; $i++) { $cards_user_val .= '$' . $i; $cards_user_val .= $i != $len ? ', ' : ''; } $cards_user_result = pg_query_params($db_lnk, 'INSERT INTO cards_users (' . $cards_user_fields . ') VALUES (' . $cards_user_val . ') RETURNING id', $cards_user_values); } } } } } } } } } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/checklists') { if (isset($checklist_id) && !empty($checklist_id)) { $qry_val_arr = array($r_post['user_id'], $response['id'], $checklist_id); pg_query_params($db_lnk, 'INSERT INTO checklist_items (created, modified, user_id, card_id, checklist_id, name, is_completed, position) SELECT created, modified, $1, card_id, $2, name, false, position FROM checklist_items WHERE checklist_id = $3', $qry_val_arr); } $qry_val_arr = array($response['id']); $result = pg_query_params($db_lnk, 'SELECT * FROM checklists_listing WHERE id = $1', $qry_val_arr); $response['checklist'] = pg_fetch_assoc($result); $response['checklist']['checklists_items'] = json_decode($response['checklist']['checklists_items'], true); $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['list_id'] = $r_resource_vars['lists']; $foreign_ids['card_id'] = $r_resource_vars['cards']; $comment = '##USER_NAME## added checklist ##CHECKLIST_NAME## to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_checklist', $foreign_ids, '', $response['id']); } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/comments') { $id_converted = base_convert($response['id'], 10, 36); $materialized_path = sprintf("%08s", $id_converted); if (!empty($prev_message['materialized_path'])) { $materialized_path = $prev_message['materialized_path'] . '-' . $materialized_path; } if (!empty($prev_message['path'])) { $path = $prev_message['path'] . '.P' . $response['id']; $depth = $prev_message['depth'] + 1; $root = $prev_message['root']; $response['activities']['depth'] = $depth; } else { $path = 'P' . $response['id']; $depth = 0; $root = $response['id']; } $qry_val_arr = array($materialized_path, $path, $depth, $root, $response['id']); pg_query_params($db_lnk, 'UPDATE activities SET materialized_path = $1, path = $2, depth = $3, root = $4 WHERE id = $5', $qry_val_arr); $qry_val_arr = array($r_post['freshness_ts'], $root); pg_query_params($db_lnk, 'UPDATE activities SET freshness_ts = $1 WHERE root = $2', $qry_val_arr); $qry_val_arr = array($root); $act_res = pg_query_params($db_lnk, 'SELECT * FROM activities WHERE root = $1', $qry_val_arr); $response['activity'] = pg_fetch_assoc($act_res); } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/copy') { if ($is_keep_attachment) { $qry_val_arr = array($response['id'], $r_post['list_id'], $r_post['board_id'], $copied_card_id); pg_query_params($db_lnk, 'INSERT INTO card_attachments (created, modified, card_id, name, path, mimetype, list_id, board_id) SELECT created, modified, $1, name, path, mimetype, $2, $3 FROM card_attachments WHERE card_id = $4 ORDER BY id', $qry_val_arr); } if ($is_keep_user) { $qry_val_arr = array($response['id'], $copied_card_id); pg_query_params($db_lnk, 'INSERT INTO cards_users (created, modified, card_id, user_id) SELECT created, modified, $1, user_id FROM cards_users WHERE card_id = $2 ORDER BY id', $qry_val_arr); } if ($is_keep_label) { $qry_val_arr = array($response['id'], $r_post['list_id'], $r_post['board_id'], $copied_card_id); pg_query_params($db_lnk, 'INSERT INTO cards_labels (created, modified, card_id, label_id, list_id, board_id) SELECT created, modified, $1, label_id, $2, $3 FROM cards_labels WHERE card_id = $4 ORDER BY id', $qry_val_arr); } if ($is_keep_activity) { $qry_val_arr = array($response['id'], $r_post['user_id'], $r_post['list_id'], $r_post['board_id'], $copied_card_id); pg_query_params($db_lnk, 'INSERT INTO activities (created, modified, card_id, user_id, list_id, board_id, foreign_id, type, comment, revisions, root, freshness_ts, depth, path, materialized_path) SELECT created, modified, $1, $2, $3, $4, foreign_id, type, comment, revisions, root, freshness_ts, depth, path, materialized_path FROM activities WHERE type = \'add_comment\' AND card_id = $5 ORDER BY id', $qry_val_arr); } if ($is_keep_checklist) { $qry_val_arr = array($response['id'], $copied_card_id); pg_query_params($db_lnk, 'INSERT INTO checklists (created, modified, user_id, card_id, name, checklist_item_count, checklist_item_completed_count, position) SELECT created, modified, user_id, $1, name, checklist_item_count, checklist_item_completed_count, position FROM checklists WHERE card_id = $2 ORDER BY id', $qry_val_arr); $qry_val_arr = array($response['id']); $checklists = pg_query_params($db_lnk, 'SELECT id FROM checklists WHERE card_id = $1', $qry_val_arr); $qry_val_arr = array($copied_card_id); $prev_checklists = pg_query_params($db_lnk, 'SELECT id FROM checklists WHERE card_id = $1', $qry_val_arr); $prev_checklist_ids = array(); while ($prev_checklist_id = pg_fetch_assoc($prev_checklists)) { $prev_checklist_ids[] = $prev_checklist_id['id']; } $i = 0; while ($checklist_id = pg_fetch_assoc($checklists)) { $qry_val_arr = array($response['id'], $checklist_id['id'], $prev_checklist_ids[$i]); pg_query_params($db_lnk, 'INSERT INTO checklist_items (created, modified, user_id, card_id, name, checklist_id, is_completed, position) SELECT created, modified, user_id, $1, name , $2, is_completed, position FROM checklist_items WHERE checklist_id = $3 ORDER BY id', $qry_val_arr); $i++; } } $foreign_ids['board_id'] = $r_post['board_id']; $foreign_ids['list_id'] = $r_post['list_id']; $foreign_ids['card_id'] = $response['id']; $comment = '##USER_NAME## copied this card "' . $srow['name'] . '" to ##CARD_NAME##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'copy_card', $foreign_ids, null, $response['id']); $qry_val_arr = array($response['id']); $response['cards'] = executeQuery('SELECT * FROM cards_listing WHERE id = $1', $qry_val_arr); if (!empty($response['cards']['cards_checklists'])) { $response['cards']['cards_checklists'] = json_decode($response['cards']['cards_checklists'], true); } if (!empty($response['cards']['cards_users'])) { $response['cards']['cards_users'] = json_decode($response['cards']['cards_users'], true); } if (!empty($response['cards']['cards_voters'])) { $response['cards']['cards_voters'] = json_decode($response['cards']['cards_voters'], true); } if (!empty($response['cards']['cards_subscribers'])) { $response['cards']['cards_subscribers'] = json_decode($response['cards']['cards_subscribers'], true); } if (!empty($response['cards']['cards_labels'])) { $response['cards']['cards_labels'] = json_decode($response['cards']['cards_labels'], true); } $qry_val_arr = array($response['id']); $activities = executeQuery('SELECT ( SELECT array_to_json(array_agg(row_to_json(cl.*))) AS array_to_json FROM ( SELECT activities_listing.* FROM activities_listing activities_listing WHERE (activities_listing.card_id = cards.id) ORDER BY activities_listing.id DESC) cl) AS activities FROM cards cards WHERE id = $1', $qry_val_arr); if (!empty($activities)) { $response['cards']['activities'] = json_decode($activities['activities'], true); } $qry_val_arr = array($response['id']); $attachments = pg_query_params($db_lnk, 'SELECT * FROM card_attachments WHERE card_id = $1', $qry_val_arr); while ($attachment = pg_fetch_assoc($attachments)) { $response['cards']['attachments'][] = $attachment; } } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/users/?') { $qry_val_arr = array($r_post['card_id'], $r_post['user_id']); $sel_query = 'SELECT cu.card_id, cu.user_id, users.username, c.board_id, c.list_id, b.name as board_name FROM cards_users cu LEFT JOIN cards c ON cu.card_id = c.id LEFT JOIN users ON cu.user_id = users.id LEFT JOIN boards b ON c.board_id = b.id WHERE cu.card_id = $1 AND cu.user_id = $2'; $get_details = pg_query_params($db_lnk, $sel_query, $qry_val_arr); $sel_details = pg_fetch_assoc($get_details); $foreign_ids['board_id'] = $sel_details['board_id']; $foreign_ids['list_id'] = $sel_details['list_id']; $foreign_ids['card_id'] = $r_post['card_id']; $qry_val_arr = array($r_post['user_id']); $user = executeQuery('SELECT * FROM users WHERE id = $1', $qry_val_arr); if ($user) { $emailFindReplace = array('mail' => 'newprojectuser', '##USERNAME##' => $user['username'], '##CURRENT_USER##' => $authUser['username'], '##BOARD_NAME##' => $sel_details['board_name'], '##BOARD_URL##' => 'http://' . $_SERVER['HTTP_HOST'] . '/#/board/' . $foreign_ids['board_id'] . '/card/' . $foreign_ids['card_id'], 'to' => $user['email']); sendMail($emailFindReplace); } $comment = '##USER_NAME## added "' . $sel_details['username'] . '" as member to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_user', $foreign_ids, '', $response['id']); } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/attachments') { $foreign_ids['board_id'] = $r_post['board_id']; $foreign_ids['list_id'] = $r_post['list_id']; $foreign_ids['card_id'] = $r_post['card_id']; $comment = '##USER_NAME## added attachment to this card ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_attachment', $foreign_ids, null, $response['id']); foreach ($thumbsizes['CardAttachment'] as $key => $value) { $mediadir = APP_PATH . '/client/img/' . $key . '/CardAttachment/' . $response['id']; $list = glob($mediadir . '.*'); @unlink($list[0]); } } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/card_voters') { $qry_val_arr = array($r_resource_vars['cards']); $previous_value = executeQuery('SELECT name FROM cards WHERE id = $1', $qry_val_arr); $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['list_id'] = $r_resource_vars['lists']; $foreign_ids['card_id'] = $r_post['card_id']; $comment = '##USER_NAME## voted on ##CARD_LINK##'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_card_voter', $foreign_ids, '', $response['id']); $qry_val_arr = array($response['id']); $s_result = pg_query_params($db_lnk, 'SELECT * FROM card_voters_listing WHERE id = $1', $qry_val_arr); $user = pg_fetch_assoc($s_result); $response['card_voters'] = $user; } else { if ($r_resource_cmd == '/boards/?/users') { $qry_val_arr = array($r_post['board_id']); $s_result = pg_query_params($db_lnk, 'SELECT name FROM boards WHERE id = $1', $qry_val_arr); $previous_value = pg_fetch_assoc($s_result); $foreign_ids['board_id'] = $r_resource_vars['boards']; $foreign_ids['board_id'] = $r_post['board_id']; $qry_val_arr = array($r_post['user_id']); $user = executeQuery('SELECT * FROM users WHERE id = $1', $qry_val_arr); if ($user) { $emailFindReplace = array('mail' => 'newprojectuser', '##USERNAME##' => $user['username'], '##CURRENT_USER##' => $authUser['username'], '##BOARD_NAME##' => $previous_value['name'], '##BOARD_URL##' => 'http://' . $_SERVER['HTTP_HOST'] . '/#/board/' . $r_post['board_id'], 'to' => $user['email']); sendMail($emailFindReplace); } $comment = '##USER_NAME## added member to board'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_board_user', $foreign_ids, '', $response['id']); } else { if ($r_resource_cmd == '/organizations/?/users/?') { $qry_val_arr = array($response['id']); $foreign_ids['organization_id'] = $r_post['organization_id']; $foreign_id = $response['id']; $comment = '##USER_NAME## added member to organization'; $response['activity'] = insertActivity($authUser['id'], $comment, 'add_organization_user', $foreign_ids, null, $foreign_id); $response['organizations_users'] = executeQuery('SELECT * FROM organizations_users_listing WHERE id = $1', $qry_val_arr); $response['organizations_users']['boards_users'] = json_decode($response['organizations_users']['boards_users'], true); } } } } } } } } } } } } } } } } // todo: $sql set as true query not execute, so add condition ($sql !== true) if ($sql && $sql !== true && !empty($json) && !empty($response['id'])) { if ($result = pg_query_params($db_lnk, $sql, array())) { $data = array(); $count = pg_num_rows($result); $i = 0; while ($row = pg_fetch_row($result)) { if ($i == 0 && $count > 1) { echo '['; } echo $row[0]; $i++; if ($i < $count) { echo ','; } else { if ($count > 1) { echo ']'; } } } pg_free_result($result); } } else { echo json_encode($response); } }
function getJSON($target, $apikey) { $json = new Services_JSON(); //JSON 객체 생성 $content = strip_tags($target); //본문 내용에 걸려있는 모든 태그들 제거 //옵션으로 간주 될수 있는 부분을 제거 &, ', " 등등 삭제 $content = str_replace("&", " ", $content); $content = htmlspecialchars($content, ENT_QUOTES); $content = str_replace("\"", " ", $content); $content = "q='" . $content . "'"; $post = doPost("/keyword?apikey=5dc435a4c228ad63347fdadb4634935bbab3962e&output=JSON", $content, "apis.daum.net/suggest"); print_r($post); $request = "http://apis.daum.net/suggest/keyword?apikey=" . $apikey . "&output=JSON&q='" . urlencode($content) . "'"; $obj = json_decode(file_get_contents($request)); return $obj; }
* @copyright 2014-2016 Restya * @license http://restya.com/ Restya Licence * @link http://restya.com/ */ require_once 'config.inc.php'; require_once 'libs/core.php'; if (!empty($_GET['plugin'])) { $content = file_get_contents(APP_PATH . DIRECTORY_SEPARATOR . 'client' . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . $_GET['plugin'] . DIRECTORY_SEPARATOR . 'app.json'); $data = json_decode($content, true); $post_data = array('client_id' => $data['settings'][$_GET['plugin'] . '_client_id']['value'], 'client_secret' => $data['settings'][$_GET['plugin'] . '_client_secret']['value'], 'code' => $_GET['code']); if ($_GET['plugin'] == 'r_zapier') { if (file_exists(APP_PATH . '/tmp/cache/site_url_for_shell.php')) { include_once APP_PATH . '/tmp/cache/site_url_for_shell.php'; } $url = explode("//", $_server_domain_url); $post_data['redirect_uri'] = $_server_domain_url . '/apps/r_zapier/login.html'; $data['settings'][$_GET['plugin'] . '_oauth_token_url']['value'] = $url[0] . '//' . $data['settings'][$_GET['plugin'] . '_client_id']['value'] . ':' . $data['settings'][$_GET['plugin'] . '_client_secret']['value'] . '@' . $url[1] . $data['settings'][$_GET['plugin'] . '_oauth_token_url']['value']; } $format = $_GET['plugin'] == 'r_zapier' ? 'json' : 'token'; $response = doPost($data['settings'][$_GET['plugin'] . '_oauth_token_url']['value'], $post_data, $format); if (is_array($response)) { $response = json_encode($response); } $response_array = json_decode($response, true); if (json_last_error() == JSON_ERROR_NONE) { $access_token = $response_array['access_token']; } else { parse_str($response); } echo !empty($access_token) ? $access_token : 'failed'; }
function getCities($year, $period, $state, $args) { $args = array_merge($args, ['srhYear' => $year, 'srhPeriod' => $period, 'gubunCode' => 'LAND', 'sidoCode' => $state]); return doPost('http://rt.molit.go.kr/srh/getGugunListAjax.do', $args); }
function postNewChild() { $request = \Slim\Slim::getInstance()->request(); $child = json_decode($request->getBody()); $whichField = $request->params('insertOnly'); if ($child->punchCardId != 0 && $child->punchCardId > 0) { $existingChild = fetchChild($child->punchCardId); if ($existingChild == false) { doPost($child, $whichField); } } else { doPost($child, $whichField); } }
function initZabbixHost($hostgroupDatas) { $allObjects = scanRealmByText('object'); foreach ($allObjects as $object) { // get group data $groups = array(); $parentRacks = getResidentRacksData($object['id']); foreach ($parentRacks as $key => $rack) { array_push($groups, array('groupid' => $hostgroupDatas[$rack['name']])); } // set interfaces $interfaces = array(); $allocs = getObjectIPAllocations($object['id']); $current_ips = array(); foreach ($allocs as $alloc) { $interface = array('type' => 1, "main" => 0, "useip" => 1, "ip" => $alloc["addrinfo"]["ip"], "dns" => "", "port" => "10050"); array_push($interfaces, $interface); } if (count($interfaces) < 1) { $interface = array('type' => 1, "main" => 1, "useip" => 1, "ip" => "127.0.0.1", "dns" => "", "port" => "10050"); array_push($interfaces, $interface); } else { $interfaces[0]['main'] = 1; } // insert host $params = array('host' => $object['name'], 'groups' => $groups, 'interfaces' => $interfaces); $result = doPost('host.create', $params); // set result $id = isset($result['result']) ? $result['result']['hostids'][0] : -1; if ($id < 0) { http_response_code(500); exit; } } }
/** * Common method to handle GET method * * @param string $r_resource_cmd URL * @param array $r_resource_vars Array generated from URL * @param array $r_resource_filters Array generated from URL query string * * @return mixed */ function r_get($r_resource_cmd, $r_resource_vars, $r_resource_filters) { global $r_debug, $db_lnk, $authUser, $_server_domain_url; // switch case.. if taking more length, then associative array... $sql = false; $response = array(); $pg_params = array(); switch ($r_resource_cmd) { case '/users': $response['users'] = array(); $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM users_listing ul ORDER BY id DESC) as d '; break; case '/users/logout': $response['user'] = array(); $authUser = array(); break; case '/users/?/activities': $condition = ''; $condition1 = ''; if (isset($r_resource_filters['last_activity_id']) && $r_resource_filters['last_activity_id'] > 0) { $condition = ' AND al.id > $2'; $condition1 = ' AND al.id > $3'; if (!empty($r_resource_filters['type']) && $r_resource_filters['type'] == 'profile') { $condition = ' AND al.id < $2'; $condition1 = ' AND al.id < $3'; } } $val_array = array($r_resource_vars['users']); $user = executeQuery('SELECT boards_users FROM users_listing WHERE id = $1', $val_array); $board_ids = array(); if (!empty($user['boards_users'])) { $boards_users = json_decode($user['boards_users'], true); foreach ($boards_users as $boards_user) { $board_ids[] = $boards_user['board_id']; } } $org_users = pg_query_params($db_lnk, 'SELECT organization_id FROM organizations_users WHERE user_id = $1', $val_array); $org_ids = array(); while ($row = pg_fetch_assoc($org_users)) { $org_ids[] = $row['organization_id']; } if (!empty($authUser) && $authUser['role_id'] == 1 && $authUser['id'] == $r_resource_vars['users']) { $condition = !empty($r_resource_filters['last_activity_id']) ? ' WHERE al.id > $1' : ""; $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al ' . $condition . ' ORDER BY id DESC LIMIT ' . PAGING_COUNT . ') as d'; } else { if (!empty($r_resource_filters['type']) && $r_resource_filters['type'] == 'profile') { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al WHERE user_id = $1 ' . $condition . ' ORDER BY id DESC LIMIT ' . PAGING_COUNT . ') as d'; array_push($pg_params, $r_resource_vars['users']); } else { if (!empty($r_resource_filters['organization_id'])) { if (isset($r_resource_filters['last_activity_id']) && $r_resource_filters['last_activity_id'] > 0) { $condition1 = ' AND al.id > $4'; } $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al WHERE ((user_id = $1 AND board_id IN (SELECT id FROM boards WHERE organization_id = $2)) OR organization_id = ANY ( $3 )) ' . $condition1 . ' ORDER BY id DESC LIMIT ' . PAGING_COUNT . ') as d'; array_push($pg_params, $r_resource_vars['users'], $r_resource_filters['organization_id'], '{' . $r_resource_filters['organization_id'] . '}'); } else { if (!empty($r_resource_filters['type']) && ($r_resource_filters['type'] = 'all')) { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al WHERE (board_id = ANY ( $1 ) OR organization_id = ANY ( $2 ))' . $condition1 . ' ORDER BY id DESC LIMIT ' . PAGING_COUNT . ') as d'; array_push($pg_params, '{' . implode(',', $board_ids) . '}', '{' . implode(',', $org_ids) . '}'); } else { if (!empty($r_resource_filters['board_id']) && $r_resource_filters['board_id']) { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al WHERE user_id = $1 AND board_id = $2' . $condition1 . ' ORDER BY freshness_ts DESC, materialized_path ASC LIMIT ' . PAGING_COUNT . ') as d'; array_push($pg_params, $r_resource_vars['users'], $r_resource_filters['board_id']); } else { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM activities_listing al WHERE ( board_id = ANY( $1 ) OR organization_id = ANY ( $2 ) )' . $condition1 . ' ORDER BY id DESC LIMIT ' . PAGING_COUNT . ') as d'; array_push($pg_params, '{' . implode(',', $board_ids) . '}', '{' . implode(',', $org_ids) . '}'); } } } } } if (!empty($condition) || !empty($condition1)) { array_push($pg_params, $r_resource_filters['last_activity_id']); } break; case '/users/search': if (!empty($r_resource_filters['organizations'])) { $sql = 'SELECT row_to_json(d) FROM (SELECT u.id, u.username, u.profile_picture_path,u.initials FROM users u LEFT JOIN organizations_users ou ON ou.user_id = u.id WHERE u.is_active = true AND u.is_email_confirmed = true AND '; $sql .= '(ou.organization_id != $1 OR ou.user_id IS null) AND'; array_push($pg_params, $r_resource_filters['organizations']); } else { if (!empty($r_resource_filters['board_id'])) { $sql = 'SELECT row_to_json(d) FROM (SELECT u.id, u.username, u.profile_picture_path,u.initials FROM users u JOIN boards_users bu ON bu.user_id = u.id WHERE u.is_active = true AND u.is_email_confirmed = true AND '; $sql .= 'bu.board_id = $1 AND'; array_push($pg_params, $r_resource_filters['board_id']); } else { $sql = 'SELECT row_to_json(d) FROM (SELECT u.id, u.username, u.profile_picture_path,u.initials FROM users u WHERE u.is_active = true AND u.is_email_confirmed = true AND '; } } if (empty($pg_params)) { $sql .= '(LOWER(u.username) LIKE LOWER($1) OR LOWER(u.email) LIKE LOWER($2))) as d '; } else { $sql .= '(LOWER(u.username) LIKE LOWER($2) OR LOWER(u.email) LIKE LOWER($3))) as d '; } array_push($pg_params, $r_resource_filters['q'] . '%', $r_resource_filters['q'] . '%'); if (empty($r_resource_filters['q'])) { $sql = false; $response = array(); $pg_params = array(); } $table = 'users'; break; case '/users/?': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM users ul WHERE id = $1) as d '; array_push($pg_params, $r_resource_vars['users']); break; case '/users/?/boards': if (!empty($authUser)) { $val_array = array($authUser['id']); $s_result = pg_query_params($db_lnk, 'SELECT board_id FROM board_stars WHERE is_starred = true AND user_id = $1', $val_array); $response['starred_boards'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['starred_boards'][] = $row['board_id']; } $val_array = array($authUser['id']); $s_result = pg_query_params($db_lnk, 'SELECT o.id as organization_id, o.name as organization_name, bu.board_id FROM boards_users bu LEFT JOIN boards b ON b.id = bu.board_id LEFT JOIN organizations o ON o.id = b.organization_id WHERE bu.user_id = $1', $val_array); $response['user_boards'] = array(); $user_boards = array(); while ($row = pg_fetch_assoc($s_result)) { $response['user_boards'][] = $row; } } break; case '/users/?/cards': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM users_cards_listing ucl WHERE user_id = $1 ORDER BY board_id ASC) as d '; array_push($pg_params, $r_resource_vars['users']); break; case '/boards': if (!empty($r_resource_filters['type']) && $r_resource_filters['type'] == 'simple') { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM simple_board_listing ul '; if (!empty($authUser) && $authUser['role_id'] != 1) { $val_array = array($authUser['id']); $s_result = pg_query_params($db_lnk, 'SELECT board_id FROM board_stars WHERE user_id = $1', $val_array); $response['starred_boards'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['starred_boards'][] = $row['board_id']; } $s_result = pg_query_params($db_lnk, 'SELECT board_id FROM boards_users WHERE user_id = $1', $val_array); $response['user_boards'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['user_boards'][] = $row['board_id']; } $board_ids = array_merge($response['starred_boards'], $response['user_boards']); $ids = 0; if (!empty($board_ids)) { $board_ids = array_unique($board_ids); $ids = '{' . implode($board_ids, ',') . '}'; } $sql .= 'WHERE ul.id =ANY($1)'; array_push($pg_params, $ids); } $sql .= ' ORDER BY name ASC) as d '; if ($authUser['role_id'] != 1 && empty($board_ids)) { $sql = false; } } else { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM boards_listing ul '; if (!empty($authUser) && $authUser['role_id'] != 1) { $val_array = array($authUser['id']); $s_result = pg_query_params($db_lnk, 'SELECT board_id FROM board_subscribers WHERE user_id = $1', $val_array); $response['starred_boards'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['starred_boards'][] = $row['board_id']; } $s_result = pg_query_params($db_lnk, 'SELECT board_id FROM boards_users WHERE user_id = $1', $val_array); $response['user_boards'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['user_boards'][] = $row['board_id']; } $board_ids = array_merge($response['starred_boards'], $response['user_boards']); $ids = 0; if (!empty($board_ids)) { $board_ids = array_unique($board_ids); $ids = '{' . implode($board_ids, ',') . '}'; } $sql .= 'WHERE ul.id = ANY ($1)'; array_push($pg_params, $ids); } $sql .= ' ORDER BY name ASC) as d '; if ($authUser['role_id'] != 1 && empty($board_ids)) { $sql = false; } } break; case '/settings/?': $response = array(); $sql = false; $s_sql = 'SELECT id, name, parent_id FROM setting_categories WHERE parent_id IS null ORDER BY "order" ASC'; $s_result = pg_query_params($db_lnk, $s_sql, array()); while ($row = pg_fetch_assoc($s_result)) { if ($row['id'] == $r_resource_vars['settings'] || $row['parent_id'] == $r_resource_vars['settings']) { $s_sql = 'SELECT s.*, sc.name as category_name FROM settings s LEFT JOIN setting_categories sc ON sc.id = s.setting_category_id WHERE setting_category_id = $1 OR setting_category_parent_id = $2 ORDER BY "order" ASC'; $s_val = array($row['id'], $row['id']); $ss_result = pg_query_params($db_lnk, $s_sql, $s_val); while ($srow = pg_fetch_assoc($ss_result)) { $row['settings'][] = $srow; } } $response[] = $row; } break; case '/email_templates/?': $response = array(); $sql = false; $s_sql = 'SELECT id, display_name FROM email_templates ORDER BY id ASC'; $s_result = pg_query_params($db_lnk, $s_sql, array()); while ($row = pg_fetch_assoc($s_result)) { if ($row['id'] == $r_resource_vars['email_templates']) { $s_sql = 'SELECT from_email, reply_to_email, name, description, subject, email_text_content, email_variables, display_name FROM email_templates WHERE id = $1'; $s_val = array($row['id']); $ss_result = pg_query_params($db_lnk, $s_sql, $s_val); while ($srow = pg_fetch_assoc($ss_result)) { $row['template'] = $srow; } } $response[] = $row; } break; case '/boards/?': $s_sql = 'SELECT b.board_visibility, bu.user_id FROM boards AS b LEFT JOIN boards_users AS bu ON bu.board_id = b.id WHERE b.id = $1'; $arr[] = $r_resource_vars['boards']; if (!empty($authUser) && $authUser['role_id'] != 1) { $s_sql .= ' AND (b.board_visibility = 2 OR bu.user_id = $2)'; $arr[] = $authUser['id']; } else { if (empty($authUser)) { $s_sql .= ' AND b.board_visibility = 2 '; } } $check_visibility = executeQuery($s_sql, $arr); if (!empty($check_visibility)) { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM boards_listing ul WHERE id = $1 ORDER BY id DESC) as d '; array_push($pg_params, $r_resource_vars['boards']); } else { $response['error']['type'] = 'visibility'; $response['error']['message'] = 'Unauthorized'; } break; case '/organizations': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM organizations_listing'; if (!empty($authUser) && $authUser['role_id'] != 1) { $sql .= ' WHERE user_id = $1'; array_push($pg_params, $authUser['id']); } $sql .= ' ORDER BY id ASC) as d '; break; case '/organizations/?': $s_sql = 'SELECT o.organization_visibility, ou.user_id FROM organizations AS o LEFT JOIN organizations_users AS ou ON ou.organization_id = o.id WHERE o.id = $1'; $arr[] = $r_resource_vars['organizations']; if (!empty($authUser) && $authUser['role_id'] != 1) { $s_sql .= ' AND (o.organization_visibility = 1 OR ou.user_id = $2)'; $arr[] = $authUser['id']; } else { if (empty($authUser)) { $s_sql .= ' AND o.organization_visibility = 1 '; } } $check_visibility = executeQuery($s_sql, $arr); if (!empty($check_visibility)) { $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM organizations_listing ul WHERE id = $1 ORDER BY id DESC) as d '; array_push($pg_params, $r_resource_vars['organizations']); } else { $response['error']['type'] = 'visibility'; $response['error']['message'] = 'Unauthorized'; } break; case '/boards/?/activities': $condition = ''; if (isset($r_resource_filters['last_activity_id']) && $r_resource_filters['last_activity_id'] > 0) { if (!empty($r_resource_filters['type']) && $r_resource_filters['type'] == 'all') { $condition = ' AND al.id < $2'; } else { $condition = ' AND al.id > $2'; } } $sql = 'SELECT row_to_json(d) FROM (SELECT al.*, c.name as card_name FROM activities_listing al left join cards c on al.card_id = c.id WHERE al.board_id = $1' . $condition . ' ORDER BY al.id DESC LIMIT ' . PAGING_COUNT . ') as d '; array_push($pg_params, $r_resource_vars['boards']); if (!empty($condition)) { array_push($pg_params, $r_resource_filters['last_activity_id']); } break; case '/boards/?/boards_stars': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM board_stars bs WHERE board_id = $1'; array_push($pg_params, $r_resource_vars['boards']); if (!empty($authUser) && $authUser['role_id'] != 1) { $sql .= ' and user_id = $2'; array_push($pg_params, $authUser['id']); } $sql .= ' ORDER BY id DESC) as d '; break; case '/boards/?/board_subscribers': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM board_subscribers ul WHERE board_id = $1'; array_push($pg_params, $r_resource_vars['boards']); if (!empty($authUser) && $authUser['role_id'] != 1) { $sql .= ' and user_id = $2'; array_push($pg_params, $authUser['id']); } $sql .= ' ORDER BY id DESC) as d '; break; case '/boards/search': $sql = 'SELECT row_to_json(d) FROM (SELECT id, name, background_color FROM boards ul WHERE name ILIKE $1 ORDER BY id DESC) as d '; array_push($pg_params, '%' . $r_resource_filters['q'] . '%'); break; case '/boards/?/lists/?/cards/?': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM cards_listing cll WHERE id = $1) as d '; array_push($pg_params, $r_resource_vars['cards']); break; case '/boards/?/lists/?/cards/?/activities': $sql = 'SELECT row_to_json(d) FROM (SELECT al.*, u.username, u.profile_picture_path, u.initials, c.description, c.name as card_name FROM activities_listing al LEFT JOIN users u ON al.user_id = u.id LEFT JOIN cards c ON al.card_id = c.id WHERE card_id = $1 ORDER BY freshness_ts DESC, materialized_path ASC) as d '; array_push($pg_params, $r_resource_vars['cards']); break; case '/activities': $condition = ''; if (isset($r_resource_filters['last_activity_id'])) { $condition = ' WHERE al.id < $1'; } $sql = 'SELECT row_to_json(d) FROM (SELECT al.*, u.username, u.profile_picture_path, u.initials, c.description FROM activities_listing al LEFT JOIN users u ON al.user_id = u.id LEFT JOIN cards c ON al.card_id = c.id ' . $condition . ' ORDER BY id DESC limit ' . PAGING_COUNT . ') as d '; if (!empty($condition)) { array_push($pg_params, $r_resource_filters['last_activity_id']); } break; case '/boards/?/lists/?/cards/?/checklists': $sql = 'SELECT row_to_json(d) FROM (SELECT * FROM checklist_add_listing al WHERE board_id = $1) as d '; array_push($pg_params, $r_resource_vars['boards']); break; case '/boards/?/visibility': $sql = 'SELECT board_visibility FROM boards bl WHERE bl.id = $1'; array_push($pg_params, $r_resource_vars['boards']); break; case '/workflow_templates': $files = glob(APP_PATH . '/client/js/workflow_templates/*.json', GLOB_BRACE); $i = 0; foreach ($files as $file) { $file_name = basename($file, '.json'); $data = file_get_contents($file); $json = json_decode($data, true); $response[] = array('name' => $json['name'], 'value' => implode($json['lists'], ', ')); } break; case '/search': if (isset($_GET['q'])) { $q_string = $_GET['q']; preg_match_all('/(?P<name>\\w+):(?P<search>\\w+)/', $q_string, $search); if (!empty($search['name'])) { foreach ($search['name'] as $key => $name) { $filter['term'][$name . '_name'] = $search['search'][$key]; $filter_query['match'][$name . '_name'] = $search['search'][$key]; } } preg_match_all('/(.*)@(?P<search>\\w+)/', $q_string, $user_search); if (!empty($user_search['search'])) { foreach ($user_search['search'] as $value) { $filter['term']['user_name'] = $value; $filter_query['match']['user_name'] = $value; } } preg_match_all('/(.*)#(?P<search>\\w+)/', $q_string, $label_search); if (!empty($label_search['search'])) { foreach ($user_search['search'] as $value) { $filter['term']['label_name'] = $value; $filter_query['match']['label_name'] = $value; } } $response = array(); if (!empty($r_resource_filters['q'])) { $elasticsearch_url = ELASTICSEARCH_URL . ELASTICSEARCH_INDEX . '/cards/_search?q=*' . $r_resource_filters['q'] . '*'; $search_response = doGet($elasticsearch_url); $response['result'] = array(); if (!empty($search_response['hits']['hits'])) { foreach ($search_response['hits']['hits'] as $result) { $s_val = array($result['_source']['board_id']); $s_result = executeQuery('SELECT board_visibility,user_id FROM boards WHERE id = $1', $s_val); if ($s_result['board_visibility'] == '2' || $s_result['user_id'] == $authUser['id'] || $authUser['role_id'] == 1) { $card['name'] = $result['_source']['card_name']; $card['id'] = $result['_id']; $card['list_name'] = $result['_source']['list_name']; $card['list_id'] = $result['_source']['list_id']; $card['board_name'] = $result['_source']['board_name']; $card['board_id'] = $result['_source']['board_id']; $card['type'] = $result['_type']; $response['result'][] = $card; } } } $elasticsearch_params['suggest']['text'] = $r_resource_filters['q']; $elasticsearch_params['suggest']['card-name-suggest']['term']['size'] = 5; $elasticsearch_params['suggest']['card-name-suggest']['term']['field'] = 'card_name'; $elasticsearch_params['suggest']['card-description-suggest']['term']['size'] = 5; $elasticsearch_params['suggest']['card-description-suggest']['term']['field'] = 'card_description'; $elasticsearch_url = ELASTICSEARCH_URL . ELASTICSEARCH_INDEX . '/_search'; $result_arr = doPost($elasticsearch_url, $elasticsearch_params, 'json'); $words = $r_resource_filters['q']; $word_count = str_word_count($words); $word_arr = explode(' ', $words); $tmp_suggested_arr = array(); $max_suggested_count = 0; if (!empty($result_arr['suggest']['card-name-suggest'])) { for ($i = 0; $i < count($result_arr['suggest']['card-name-suggest']); $i++) { for ($j = 0; $j <= 2; $j++) { if (!empty($result_arr['suggest']['card-name-suggest'][$i]['options'][$j]['text'])) { $tmp_suggested_arr[$i][] = $result_arr['suggest']['card-name-suggest'][$i]['options'][$j]['text']; } if (!empty($result_arr['suggest']['card-description-suggest'][$i]['options'][$j]['text'])) { $tmp_suggested_arr[$i][] = $result_arr['suggest']['card-description-suggest'][$i]['options'][$j]['text']; } } if (!empty($tmp_suggested_arr[$i])) { $tmp_suggested_arr[$i] = array_unique($tmp_suggested_arr[$i]); if (count($tmp_suggested_arr[$i]) > $max_suggested_count) { $max_suggested_count = count($tmp_suggested_arr[$i]); } } } } $response['suggestion'] = array(); if (!empty($tmp_suggested_arr)) { for ($i = 0; $i < $max_suggested_count; $i++) { $response['suggestion'][$i] = ''; for ($j = 0; $j < $word_count; $j++) { if (isset($response[$i])) { $response[$i] .= ' '; } $response['suggestion'][$i] .= !empty($tmp_suggested_arr[$j][$i]) ? $tmp_suggested_arr[$j][$i] : (!empty($tmp_suggested_arr[$j][0]) ? $tmp_suggested_arr[$j][0] : $word_arr[$j]); } } } $response['suggestion'] = array_unique($response['suggestion']); } } break; case '/boards/?/lists/?/cards/?/search': $sql = 'SELECT row_to_json(d) FROM (SELECT bul.id, bul.user_id, bul.username, bul.profile_picture_path,bul.initials FROM boards_users_listing bul WHERE'; $sql .= '(bul.username LIKE $1 OR bul.email LIKE $2) AND bul.board_id = $3) as d '; array_push($pg_params, '%' . $r_resource_filters['q'] . '%', '%' . $r_resource_filters['q'] . '%', $r_resource_vars['boards']); if (empty($r_resource_filters['q'])) { $sql = false; $response = array(); $pg_params = array(); } $table = 'users'; break; case '/cards/search': $user_id = !empty($authUser['id']) ? $authUser['id'] : 0; $sql = 'SELECT row_to_json(d) FROM (SELECT DISTINCT c.id, c.name, bu.board_id FROM boards_users bu join cards c on c.board_id = bu.board_id WHERE bu.board_id IN (SELECT board_id FROM boards_users WHERE user_id = $1) AND c.name LIKE $2 ORDER BY id ASC) as d'; array_push($pg_params, $user_id, '%' . $r_resource_filters['q'] . '%'); if (empty($r_resource_filters['q'])) { $sql = false; $response = array(); $pg_params = array(); } break; case '/acl_links': $sql = false; $s_sql = 'SELECT row_to_json(d) FROM (SELECT acl_links.id, acl_links.name, acl_links.group_id, ( SELECT array_to_json(array_agg(row_to_json(alr.*))) AS array_to_json FROM ( SELECT acl_links_roles.role_id FROM acl_links_roles acl_links_roles WHERE acl_links_roles.acl_link_id = acl_links.id ORDER BY acl_links_roles.role_id) alr) AS acl_links_roles, acl_links.is_allow_only_to_admin, acl_links.is_allow_only_to_user FROM acl_links acl_links ORDER BY group_id ASC, id ASC) as d'; $s_result = pg_query_params($db_lnk, $s_sql, array()); $response['acl_links'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['acl_links'][] = json_decode($row['row_to_json'], true); } $s_sql = 'SELECT id, name FROM roles'; $s_result = pg_query_params($db_lnk, $s_sql, array()); $response['roles'] = array(); while ($row = pg_fetch_assoc($s_result)) { $response['roles'][] = $row; } break; case '/settings': $role_id = empty($user['role_id']) ? 3 : $user['role_id']; $s_sql = pg_query_params($db_lnk, 'SELECT name, value FROM settings WHERE name = \'SITE_NAME\' OR name = \'SITE_TIMEZONE\' OR name = \'DROPBOX_APPKEY\' OR name = \'LABEL_ICON\' OR name = \'FLICKR_API_KEY\' or name = \'LDAP_LOGIN_ENABLED\' or name = \'STANDARD_LOGIN_ENABLED\'', array()); while ($row = pg_fetch_assoc($s_sql)) { $response[$row['name']] = $row['value']; } break; default: header($_SERVER['SERVER_PROTOCOL'] . ' 501 Not Implemented', true, 501); } if (!empty($sql)) { $arrayResponse = array('/users/?/cards', '/users/?/activities', '/users/search', '/boards', '/boards/?/activities', '/boards/?/activities', '/boards/?/lists/?/cards/?/activities', '/boards/?/lists/?/cards/?/search', '/cards/search', '/organizations', '/activities'); if ($result = pg_query_params($db_lnk, $sql, $pg_params)) { $data = array(); $count = pg_num_rows($result); $i = 0; if (in_array($r_resource_cmd, $arrayResponse) && ($count == 1 || $count == 0)) { echo '['; } while ($row = pg_fetch_row($result)) { $obj = json_decode($row[0], true); if (isset($obj['board_activities']) && !empty($obj['board_activities'])) { for ($k = 0; $k < count($obj['board_activities']); $k++) { if (!empty($obj['board_activities'][$k]['revisions']) && trim($obj['board_activities'][$k]['revisions']) != '') { $revisions = unserialize($obj['board_activities'][$k]['revisions']); unset($dif); if (!empty($revisions['new_value'])) { foreach ($revisions['new_value'] as $key => $value) { if ($key != 'is_archived' && $key != 'is_deleted' && $key != 'created' && $key != 'modified' && $obj['type'] != 'moved_card_checklist_item' && $obj['type'] != 'add_card_desc' && $obj['type'] != 'add_card_duedate' && $obj['type'] != 'delete_card_duedate' && $obj['type'] != 'change_visibility' && $obj['type'] != 'add_background' && $obj['type'] != 'change_background') { $old_val = $revisions['old_value'][$key] != null && $revisions['old_value'][$key] != 'null' ? $revisions['old_value'][$key] : ''; $new_val = $revisions['new_value'][$key] != null && $revisions['new_value'][$key] != 'null' ? $revisions['new_value'][$key] : ''; $dif[] = nl2br(getRevisiondifference($old_val, $old_val)); } if ($obj['type'] == 'add_card_desc' || $obj['type'] == 'add_card_desc' || $obj['type'] == ' edit_card_duedate' || $obj['type'] == 'change_visibility' || $obj['type'] == 'add_background' || $obj['type'] == 'change_background') { $dif[] = $revisions['new_value'][$key]; } } if (isset($dif)) { $obj['board_activities'][$k]['difference'] = $dif; } } else { if (!empty($revisions['old_value']) && isset($obj['type']) && $obj['type'] == 'delete_card_comment') { $obj['board_activities'][$k]['difference'] = nl2br(getRevisiondifference($revisions['old_value'], '')); } } } } $row[0] = json_encode($obj); if ($r_resource_cmd == '/boards/?') { $obj = json_decode($row[0], true); global $_server_domain_url; $md5_hash = md5(SECURITYSALT . $r_resource_vars['boards']); $obj['google_syn_url'] = $_server_domain_url . '/ical/' . $r_resource_vars['boards'] . '/' . $md5_hash . '.ics'; $row[0] = json_encode($obj); } } else { if ($r_resource_cmd == '/boards/?/lists/?/cards/?/activities' || $r_resource_cmd == '/users/?/activities' || $r_resource_cmd == '/users/?/notify_count' || $r_resource_cmd == '/boards/?/activities') { if (!empty($obj['revisions']) && trim($obj['revisions']) !== '') { $revisions = unserialize($obj['revisions']); $obj['revisions'] = $revisions; unset($dif); if (!empty($revisions['new_value'])) { foreach ($revisions['new_value'] as $key => $value) { if ($key != 'is_archived' && $key != 'is_deleted' && $key != 'created' && $key != 'modified' && $key != 'is_offline' && $key != 'uuid' && $key != 'to_date' && $key != 'temp_id' && $obj['type'] != 'moved_card_checklist_item' && $obj['type'] != 'add_card_desc' && $obj['type'] != 'add_card_duedate' && $obj['type'] != 'delete_card_duedate' && $obj['type'] != 'add_background' && $obj['type'] != 'change_background' && $obj['type'] != 'change_visibility') { $old_val = isset($revisions['old_value'][$key]) && $revisions['old_value'][$key] != null && $revisions['old_value'][$key] != 'null' ? $revisions['old_value'][$key] : ''; $new_val = isset($revisions['new_value'][$key]) && $revisions['new_value'][$key] != null && $revisions['new_value'][$key] != 'null' ? $revisions['new_value'][$key] : ''; $dif[] = nl2br(getRevisiondifference($old_val, $new_val)); } if ($obj['type'] == 'add_card_desc' || $obj['type'] == 'add_card_desc' || $obj['type'] == ' edit_card_duedate' || $obj['type'] == 'add_background' || $obj['type'] == 'change_background' || $obj['type'] == 'change_visibility') { $dif[] = $revisions['new_value'][$key]; } } } else { if (!empty($revisions['old_value']) && isset($obj['type']) && $obj['type'] == 'delete_card_comment') { $dif[] = nl2br(getRevisiondifference($revisions['old_value'], '')); } } if (isset($dif)) { $obj['difference'] = $dif; } } if ($obj['type'] === 'add_board_user') { $obj_val_arr = array($obj['foreign_id']); $obj['board_user'] = executeQuery('SELECT * FROM boards_users_listing WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_list') { $obj_val_arr = array($obj['list_id']); $obj['list'] = executeQuery('SELECT * FROM lists WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'change_list_position') { $obj_val_arr = array($obj['list_id']); $obj['list'] = executeQuery('SELECT position, board_id FROM lists WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_card') { $obj_val_arr = array($obj['card_id']); $obj['card'] = executeQuery('SELECT * FROM cards WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'copy_card') { $obj_val_arr = array($obj['foreign_id']); $obj['card'] = executeQuery('SELECT * FROM cards WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_card_checklist') { $obj_val_arr = array($obj['foreign_id']); $obj['checklist'] = executeQuery('SELECT * FROM checklists_listing WHERE id = $1', $obj_val_arr); $obj['checklist']['checklists_items'] = json_decode($obj['checklist']['checklists_items'], true); } else { if ($obj['type'] === 'add_card_label') { $obj_val_arr = array($obj['card_id']); $s_result = pg_query_params($db_lnk, 'SELECT * FROM cards_labels_listing WHERE card_id = $1', $obj_val_arr); while ($row = pg_fetch_assoc($s_result)) { $obj['labels'][] = $row; } } else { if ($obj['type'] === 'add_card_voter') { $obj_val_arr = array($obj['foreign_id']); $obj['voter'] = executeQuery('SELECT * FROM card_voters_listing WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_card_user') { $obj_val_arr = array($obj['foreign_id']); $obj['user'] = executeQuery('SELECT * FROM cards_users_listing WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'update_card_checklist') { $obj_val_arr = array($obj['foreign_id']); $obj['checklist'] = executeQuery('SELECT * FROM checklists WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_checklist_item' || $obj['type'] === 'update_card_checklist_item' || $obj['type'] === 'moved_card_checklist_item') { $obj_val_arr = array($obj['foreign_id']); $obj['item'] = executeQuery('SELECT * FROM checklist_items WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'add_card_attachment') { $obj_val_arr = array($obj['foreign_id']); $obj['attachment'] = executeQuery('SELECT * FROM card_attachments WHERE id = $1', $obj_val_arr); } else { if ($obj['type'] === 'change_card_position') { $obj_val_arr = array($obj['card_id']); $obj['card'] = executeQuery('SELECT position FROM cards WHERE id = $1', $obj_val_arr); } } } } } } } } } } } } } $row[0] = json_encode($obj); } else { if ($r_resource_cmd == '/boards/?') { $obj = json_decode($row[0], true); global $_server_domain_url; $md5_hash = md5(SECURITYSALT . $r_resource_vars['boards']); $obj['google_syn_url'] = $_server_domain_url . '/ical/' . $r_resource_vars['boards'] . '/' . $md5_hash . '.ics'; $row[0] = json_encode($obj); } } } if ($i == 0 && $count > 1) { echo '['; } echo $row[0]; $i++; if ($i < $count) { echo ','; } else { if ($count > 1) { echo ']'; } } } if (in_array($r_resource_cmd, $arrayResponse) && ($count == 1 || $count == 0)) { echo ']'; } pg_free_result($result); } else { $r_debug .= __LINE__ . ': ' . pg_last_error($db_lnk) . '\\n'; } } else { echo json_encode($response); } }
<?php include_once 'langList.php'; include_once 'common.php'; echoStyle(); if (isset($_POST['strLine'], $_POST['intLine'], $_POST['fileName'])) { doPost($_POST['strLine'], $_POST['intLine'], $_POST['fileName']); } elseif (isset($_GET['lang'])) { $filename = strtolower($_GET['lang']); if ($filename != "") { if (in_array($filename, getLangFiles())) { showEdit($filename); } else { badData("LANGUAGE FILE (" . $filename . ") NOT FOUND"); } } else { badData("NO LANGUAGE FILE ENTERED"); } } else { badData("NO LANGUAGE FILE ENTERED"); } function doPost($strLine, $intLine, $fileName) { $strLine = str_replace("\\", "", $strLine); if (substr($strLine, 0, 1) != '"' or substr($strLine, -2) != '";') { showError('All lines must start with " and end with "; ', $strLine); } else { $flines = file($fileName); //Update the line $flines[$intLine] = substr($flines[$intLine], 0, 40) . $strLine . "\n"; //reWrite the file
/** * 对于集合进行了任何操作,那么出发联动事件,联动修改其他集合的相关数据 * 提交全部POST参数以及系统默认的触发参数__TRIGER__ * $_POST['__TRIGER__']['collection'] 触发事件集合的名称 * $_POST['__TRIGER__']['controller'] 触发控制器 * $_POST['__TRIGER__']['action'] 触发动作 * 为了确保调用安全,签名方法为所有POST参数按照字母顺序排列,构建的字符串substr(sha1(k1=v1&k2=v2连接密钥),0,32),做个小欺骗,让签名看起来很像MD5的。 */ public function __destruct() { fastcgi_finish_request(); try { $controller = $this->params('controller'); $action = $this->params('action'); $_POST['__TRIGER__'] = array('collection' => $this->getCollectionAliasById($this->_collection_id), 'controller' => $controller, 'action' => $action); $collectionInfo = $this->_collection->findOne(array('_id' => myMongoId($this->_collection_id), 'isAutoHook' => true)); if ($collectionInfo !== null && isset($collectionInfo['hook']) && filter_var($collectionInfo['hook'], FILTER_VALIDATE_URL) !== false) { $sign = dataSignAlgorithm($_POST, $collectionInfo['hookKey']); $_POST['__SIGN__'] = $sign; $response = doPost($collectionInfo['hook'], $_POST); $this->_collection->update(array('_id' => $collectionInfo['_id']), array('$set' => array('hookLastResponseResult' => $response))); } } catch (\Exception $e) { $this->log(exceptionMsg($e)); } return false; }
<?php require_once '../src/utils.inc.php'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { doGet(); } else { doPost(); } function doGet() { $storeName = $_GET['storeName']; $token = @$_GET['token']; $from = @$_GET['from']; $to = @$_GET['to']; $type = @$_GET['submit']; if (empty($token)) { $token = null; } if (empty($from)) { $from = date('Y-m-d'); } if (empty($to)) { $fromTime = strtotime($from); $to = date('Y-m-d', $fromTime + 24 * 60 * 60); } if (empty($type)) { $type = null; } render($storeName, $token, $from, $to, $type); } function doPost()
function getApplication($hostid) { # parameters $params = array('output' => 'extend', 'hostids' => $hostid, 'sortfield' => 'name'); return doPost('application.get', $params); }