public function testRun() { //Create 2 jobLogs, and set one with a date over a week ago (8 days ago) for the endDateTime $eightDaysAgoTimestamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $jobLog = new JobLog(); $jobLog->type = 'Monitor'; $jobLog->startDateTime = $eightDaysAgoTimestamp; $jobLog->endDateTime = $eightDaysAgoTimestamp; $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR; $jobLog->isProcessed = false; $jobLog->save(); $jobLog2 = new JobLog(); $jobLog2->type = 'ImportCleanup'; $jobLog2->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $jobLog2->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $jobLog2->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR; $jobLog2->isProcessed = false; $jobLog2->save(); $sql = 'select count(*) count from item'; $row = R::getRow($sql); $this->assertEquals(4, $row['count']); $job = new JobLogCleanupJob(); $this->assertTrue($job->run()); $jobLogs = JobLog::getAll(); $this->assertEquals(1, count($jobLogs)); $this->assertEquals($jobLog2->id, $jobLogs[0]->id); $sql = 'select count(*) count from item'; $row = R::getRow($sql); $this->assertEquals(3, $row['count']); }
/** * Tests the various ways to fetch (select queries) * data using adapter methods in the facade. * Also tests the new R::getAssocRow() method, * as requested in issue #324. */ public function testFetchTypes() { R::nuke(); $page = R::dispense('page'); $page->a = 'a'; $page->b = 'b'; R::store($page); $page = R::dispense('page'); $page->a = 'c'; $page->b = 'd'; R::store($page); $expect = '[{"id":"1","a":"a","b":"b"},{"id":"2","a":"c","b":"d"}]'; asrt(json_encode(R::getAll('SELECT * FROM page')), $expect); $expect = '{"1":"a","2":"c"}'; asrt(json_encode(R::getAssoc('SELECT id, a FROM page')), $expect); asrt(json_encode(R::getAssoc('SELECT id, a, b FROM page')), $expect); $expect = '[{"id":"1","a":"a"},{"id":"2","a":"c"}]'; asrt(json_encode(R::getAssocRow('SELECT id, a FROM page')), $expect); $expect = '[{"id":"1","a":"a","b":"b"},{"id":"2","a":"c","b":"d"}]'; asrt(json_encode(R::getAssocRow('SELECT id, a, b FROM page')), $expect); $expect = '{"id":"1","a":"a","b":"b"}'; asrt(json_encode(R::getRow('SELECT * FROM page WHERE id = 1')), $expect); $expect = '"a"'; asrt(json_encode(R::getCell('SELECT a FROM page WHERE id = 1')), $expect); $expect = '"b"'; asrt(json_encode(R::getCell('SELECT b FROM page WHERE id = 1')), $expect); $expect = '"c"'; asrt(json_encode(R::getCell('SELECT a FROM page WHERE id = 2')), $expect); $expect = '["a","c"]'; asrt(json_encode(R::getCol('SELECT a FROM page')), $expect); $expect = '["b","d"]'; asrt(json_encode(R::getCol('SELECT b FROM page')), $expect); }
function is_enduser($id) { $sql = "select not_listed_in_search from usertypes where id = (select usertype from users where id = ?)"; require_once "config.php"; $data = R::getRow($sql, array($id)); return $data["not_listed_in_search"] == 1 ? 1 : 0; }
public function testProperlyDeletingActivityItems() { Yii::app()->user->userModel = User::getByUsername('super'); $count = R::getRow('select count(*) count from activity_item'); $this->assertEquals(0, $count['count']); $account = AccountTestHelper::createAccountByNameForOwner('anAccount', Yii::app()->user->userModel); $deleted = $account->delete(); $this->assertTrue($deleted); $count = R::getRow('select count(*) count from activity_item'); $this->assertEquals(0, $count['count']); $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', Yii::app()->user->userModel); $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('anOpp', Yii::app()->user->userModel); $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', Yii::app()->user->userModel, $account2); $task->activityItems->add($opportunity); $this->assertTrue($task->save()); $taskId = $task->id; $task->forget(); RedBeansCache::forgetAll(); $count = R::getRow('select count(*) count from activity_item'); $this->assertEquals(2, $count['count']); $deleted = $account2->delete(); $this->assertTrue($deleted); $account2->forget(); $count = R::getRow('select count(*) count from activity_item'); $this->assertEquals(1, $count['count']); RedBeansCache::forgetAll(); //Make sure things render ok even with the account deleted. $content = ActivitiesUtil::renderSummaryContent(Task::getById($taskId), 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule'); }
public function testRun() { $quote = DatabaseCompatibilityUtil::getQuote(); //Create 2 imports, and set one with a date over a week ago (8 days ago) for the modifiedDateTime $import = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName()); $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $import->getClassId('Item'); R::exec($sql); $staleImportId = $import->id; $import2 = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $import2->serializedData = serialize($serializedData); $this->assertTrue($import2->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import2->getTempTableName()); $this->assertEquals(2, count(Import::getAll())); $row = R::getRow('show tables like "' . $import->getTempTableName() . '"'); $this->assertNotEmpty($row); $job = new ImportCleanupJob(); $this->assertTrue($job->run()); $row = R::getRow('show tables like "' . $import->getTempTableName() . '"'); $this->assertEmpty($row); $imports = Import::getAll(); $this->assertEquals(1, count($imports)); $this->assertEquals($import2->id, $imports[0]->id); }
public function testSaveAllMetadata() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $this->assertTrue(ContactsModule::loadStartingData()); $messageLogger = new MessageLogger(); InstallUtil::autoBuildDatabase($messageLogger); chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands'); $command = "php zurmocTest.php manageMetadata super saveAllMetadata"; if (!IS_WINNT) { $command .= ' 2>&1'; } exec($command, $output); // Check if data are saved for some specific View $moduleMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='NotesModule'"); $this->assertTrue($moduleMetadata['id'] > 0); $this->assertTrue(strlen($moduleMetadata['serializedmetadata']) > 0); // Check if data are saved for some specific View $modelMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='Note'"); $this->assertTrue($modelMetadata['id'] > 0); $this->assertTrue(strlen($modelMetadata['serializedmetadata']) > 0); // Check if data are saved for some specific View $viewMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='ContactsListView'"); $this->assertTrue($viewMetadata['id'] > 0); $this->assertTrue(strlen($viewMetadata['serializedmetadata']) > 0); }
public function countAll() { $row = R::getRow('select count(*) as count_all from `' . $this->table_name . '`'); if (isset($row['count_all'])) { return (int) $row['count_all']; } else { return 0; } }
public function getChartData() { $sql = static::makeSqlQuery(static::makeSearchAttributeData($this->autoresponder)); $row = R::getRow($sql); $data = static::resolveChartDataBaseGroupElements(); foreach ($data as $index => $notUsed) { if ($row[$index] != null) { $data[$index] = $row[$index]; } } return $data; }
public function authenticate(Request $request) { \R::setup('mysql:host=localhost;dbname=gazingle', 'root', ''); $redis = Redis::connection(); $user = \R::getRow('select * from users where email = "' . $request->email . '"'); //return $user; if ($request->password === \Crypt::decrypt($user['password'])) { \Auth::loginUsingId($user['id']); $redis->set(\Crypt::encrypt($request->email), $user['id']); return $redis->get($request->email); } return response('Unauthorized.', 401); }
public function testRecreateTable() { ReadPermissionsSubscriptionUtil::recreateTable('account_read_subscription'); $sql = 'INSERT INTO account_read_subscription VALUES (null, \'1\', \'2\', \'2013-05-03 15:16:06\', \'1\')'; R::exec($sql); $accountReadSubscription = R::getRow("SELECT * FROM account_read_subscription"); $this->assertTrue($accountReadSubscription['id'] > 0); $this->assertEquals(1, $accountReadSubscription['userid']); $this->assertEquals(2, $accountReadSubscription['modelid']); $this->assertEquals('2013-05-03 15:16:06', $accountReadSubscription['modifieddatetime']); $this->assertEquals(1, $accountReadSubscription['subscriptiontype']); $sql = 'DELETE FROM account_read_subscription'; R::exec($sql); }
/** * ユーザーが0件のときに初期ユーザーを登録する。 * * @param array $userInfo */ public static function registerInitialUser($userInfo) { if (!isset($userInfo['sub'])) { return; } $user_id = $userInfo['sub']; $row = \R::getRow('SELECT COUNT(user_id) AS count FROM user'); if ($row['count'] == 0) { $msg01 = "Administrator Group"; // 管理グループ \R::exec('INSERT INTO `grp` (`grp_name`) VALUES (?)', array($msg01)); \R::exec('INSERT INTO `user` (`user_id`, `user_name`, `password`, `role`, `admin_flag`) VALUES (?, ?, ?, ?, ?)', array($user_id, '', '', '000', 1)); \R::exec('INSERT INTO `user_grp` (`user_id`, `grp_id`) VALUES (?, ?)', array($user_id, 1)); } }
/** * @return array */ public function getChartData() { $chartData = array(); $groupedDateTimeData = static::makeGroupedDateTimeData($this->beginDate, $this->endDate, $this->groupBy, false); foreach ($groupedDateTimeData as $groupData) { $beginDateTime = DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($groupData['beginDate']); $endDateTime = DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($groupData['endDate']); $searchAttributedata = static::makeSearchAttributeData($endDateTime, $this->marketingList); $sql = static::makeColumnSqlQuery($beginDateTime, $searchAttributedata); $row = R::getRow($sql); $columnData = array(MarketingChartDataProvider::NEW_SUBSCRIBERS_COUNT => ArrayUtil::getArrayValueAndResolveNullAsZero($row, static::NEW_SUBSCRIBERS_COUNT), MarketingChartDataProvider::EXISTING_SUBSCRIBERS_COUNT => ArrayUtil::getArrayValueAndResolveNullAsZero($row, static::EXISTING_SUBSCRIBERS_COUNT), 'displayLabel' => $groupData['displayLabel'], 'dateBalloonLabel' => $this->resolveDateBalloonLabel($groupData['displayLabel'])); $chartData[] = $columnData; } return $chartData; }
public function printOverallHoneypotActivity() { //TOTAL LOGIN ATTEMPTS $db_query = "SELECT COUNT(*) AS logins FROM connections"; $row = R::getRow($db_query); //echo '<strong>Total login attempts: </strong><h3>'.$row['logins'].'</h3>'; echo '<table><thead>'; echo '<tr>'; echo '<th>Total attack attempts</th>'; echo '<th>' . $row['logins'] . '</th>'; echo '</tr></thead><tbody>'; echo '</tbody></table>'; //TOTAL DISTINCT IPs $db_query = "SELECT COUNT(DISTINCT source_ip) AS ips FROM connections"; $row = R::getRow($db_query); //echo '<strong>Distinct source IPs: </strong><h3>'.$row['IPs'].'</h3>'; echo '<table><thead>'; echo '<tr>'; echo '<th>Distinct source IP addresses</th>'; echo '<th>' . $row['ips'] . '</th>'; echo '</tr></thead><tbody>'; echo '</tbody></table>'; //OPERATIONAL TIME PERIOD $db_query = "SELECT MIN(timestamp) AS start, MAX(timestamp) AS end FROM connections"; $rows = R::getAll($db_query); if (count($rows)) { //We create a skeleton for the table echo '<table><thead>'; echo '<tr class="dark">'; echo '<th colspan="2">Active time period</th>'; echo '</tr>'; echo '<tr class="dark">'; echo '<th>Start date (first attack)</th>'; echo '<th>End date (last attack)</th>'; echo '</tr></thead><tbody>'; //For every row returned from the database we add a new point to the dataset, //and create a new table row with the data as columns foreach ($rows as $row) { echo '<tr class="light">'; echo '<td>' . date('l, d-M-Y, H:i A', strtotime($row['start'])) . '</td>'; echo '<td>' . date('l, d-M-Y, H:i A', strtotime($row['end'])) . '</td>'; echo '</tr>'; } //Close tbody and table element, it's ready. echo '</tbody></table>'; } }
public function testRebuilt() { ModelCreationApiSyncUtil::buildTable(); $sql = 'INSERT INTO ' . ModelCreationApiSyncUtil::TABLE_NAME . ' VALUES (null, \'ApiServiceName\', \'1\', \'Contact\', \'2013-05-03 15:16:06\')'; R::exec($sql); $apiServiceCreationRow = R::getRow('SELECT * FROM ' . ModelCreationApiSyncUtil::TABLE_NAME); $this->assertTrue($apiServiceCreationRow['id'] > 0); $this->assertEquals('ApiServiceName', $apiServiceCreationRow['servicename']); $this->assertEquals(1, $apiServiceCreationRow['modelid']); $this->assertEquals('Contact', $apiServiceCreationRow['modelclassname']); $this->assertEquals('2013-05-03 15:16:06', $apiServiceCreationRow['createddatetime']); // Now test when table already exist ModelCreationApiSyncUtil::buildTable(); $apiServiceCreationRow = R::getRow('SELECT COUNT(*) as totalRows FROM ' . ModelCreationApiSyncUtil::TABLE_NAME); $this->assertEquals(1, $apiServiceCreationRow['totalRows']); $sql = 'INSERT INTO ' . ModelCreationApiSyncUtil::TABLE_NAME . ' VALUES (null, \'ApiServiceName\', \'2\', \'Contact\', \'2013-06-03 15:16:06\')'; R::exec($sql); $apiServiceCreationRow = R::getRow('SELECT COUNT(*) as totalRows FROM ' . ModelCreationApiSyncUtil::TABLE_NAME); $this->assertEquals(2, $apiServiceCreationRow['totalRows']); }
} $people_array = json_decode($peoples); if ($people_array === FALSE || $people_array == NULL || empty($people_array)) { //header('Content-type:text/json;charset=utf-8'); //echo json_encode(['result' => 'failed', 'error' => 'invalid argument peoples']); //die(); } // Get user info R::addDatabase('kayako', $GLOBALS['db_kayako_url'], $GLOBALS['db_kayako_user'], $GLOBALS['db_kayako_pass']); R::selectDatabase('kayako'); if (!R::testConnection()) { exit('DB failed' . PHP_EOL); } R::freeze(true); try { $user = R::getRow(' SELECT su.userid,' . ' su.fullname, ' . ' sm.email,' . ' su.phone,' . ' su.userorganizationid,' . ' so.organizationname ' . ' FROM kayako_fusion.swusers su' . ' INNER JOIN kayako_fusion.swuseremails sm' . ' ON su.userid = sm.linktypeid' . ' AND sm.linktype = 1' . ' INNER JOIN kayako_fusion.swuserorganizations so' . ' ON so.userorganizationid = su.userorganizationid' . ' WHERE email = :email', [':email' => $user_name]); } catch (Exception $e) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]); die; } R::close(); // Save frequent people R::addDatabase('supportsr', $GLOBALS['db_supportsr_url'], $GLOBALS['db_supportsr_user'], $GLOBALS['db_supportsr_pass']); R::selectDatabase('supportsr'); if (!R::testConnection()) { exit('DB failed' . PHP_EOL); } R::freeze(true); try { R::begin();
function inheritanceForm($db, $pj_id, $sop_id, $tpl_id) { // 同じSOPに所属するテンプレートの中で一番新しいものを取得。 $sql = getSQLBaseForTplList() . " AND tpl.pj_id = :pj_id AND tpl.sop_id = :sop_id AND tpl.tpl_id < :tpl_id ORDER BY tpl.tpl_id DESC LIMIT 1"; $row = R::getRow($sql, array(':pj_id' => $pj_id, ':sop_id' => $sop_id, ':tpl_id' => $tpl_id)); if (!$row) { return; } $src_tpl_id = $row['tpl_id']; $sql = getSQLBaseForFormList() . " AND pj_id = :pj_id AND sop_id = :sop_id AND tpl_id = :tpl_id ORDER BY form_id"; foreach (R::getAll($sql, array(':pj_id' => $pj_id, ':sop_id' => $sop_id, ':tpl_id' => $src_tpl_id)) as $form) { addForm($db, $pj_id, $sop_id, $tpl_id, $form['x'], $form['y'], $form['width'], $form['height'], $form['type'], $form['default_value']); } }
_log(json_encode(['staff_id_or_name' => $staff_id_or_name, 'staff_id' => $staff_id, 'ticket_id' => $ticket_id])); // Check if (empty($staff_id_or_name) || empty($ticket_id)) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'missing argument']); die; } // Query get name, title, skill R::addDatabase('portal', $GLOBALS['db_portal_url'], $GLOBALS['db_portal_user'], $GLOBALS['db_portal_pass']); R::selectDatabase('portal'); if (!R::testConnection()) { exit('DB failed' . PHP_EOL); } R::freeze(true); try { $staff_skills = R::getRow(' SELECT s2.name AS staff_name,' . ' IFNULL(dict.text, "-") AS job_title,' . ' IFNULL(s2.img_url, "") AS staff_photo,' . ' IFNULL(GROUP_CONCAT(",", k.name), "-") AS skill_name,' . ' 0 AS rate_score,' . ' 0 AS experience_count' . ' FROM portal.p_stuff s2' . ' LEFT JOIN p_dict_info dict' . ' ON dict.value = s2.station' . ' AND dict.dict_name = "PEOPLE_STATION"' . ' LEFT JOIN portal.p_stuff_skill_r r' . ' ON s2.id = r.stuff_id' . ' LEFT JOIN portal.p_skill k' . ' ON r.skill_id = k.id' . ' WHERE s2.name = :staff_name' . ' GROUP BY s2.name,' . ' s2.station,' . ' s2.img_url' . ' LIMIT 1', [':staff_name' => $staff_id_or_name]); } catch (Exception $e) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]); die; } R::close(); // Query rating and experience count R::addDatabase('kayako', $GLOBALS['db_kayako_url'], $GLOBALS['db_kayako_user'], $GLOBALS['db_kayako_pass']); R::selectDatabase('kayako'); if (!R::testConnection()) { exit('DB failed' . PHP_EOL); } R::freeze(true); try { $staff_rate_score = R::getCell(' SELECT AVG(rating_result) AS rate_score' . ' FROM supportsr.esr_workorder_assignee_rating r' . ' WHERE r.workorder_assignee = :workorder_assignee' . ' GROUP BY r.workorder_assignee', [':workorder_assignee' => $staff_id_or_name]);
_log(json_encode(['supportsr_request_id' => $supportsr_request_id])); // Check if (empty($supportsr_request_id)) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'missing argument']); die; } // Query R::addDatabase('kayako', $GLOBALS['db_kayako_url'], $GLOBALS['db_kayako_user'], $GLOBALS['db_kayako_pass']); R::selectDatabase('kayako'); if (!R::testConnection()) { exit('DB failed' . PHP_EOL); } R::freeze(true); try { $request_detail = R::getRow('SELECT dbname AS dc_name,' . ' cb_people,' . ' cb_equipment,' . ' TRIM(TRAILING "," FROM CONCAT(' . ' IF(cb_visit = "yes", "参观访问,", ""),' . ' IF(cb_installation = "yes", "安装调试,", ""),' . ' IF(cb_operation = "yes", "运行维护,", ""),' . ' IF(cb_line = "yes", "线路安装,", ""),' . ' IF(cb_practice = "yes", "灾备演练,", ""),' . ' IF(cb_audit = "yes", "检查/审计,", ""),' . ' IF(cb2_other = "yes", "其他,", "")' . ' )) AS request_purpose,' . ' start_time,' . ' end_time' . ' FROM supportsr.esr_peopleequipment_inoutrequest' . ' WHERE id = :supportsr_request_id', [':supportsr_request_id' => $supportsr_request_id]); } catch (Exception $e) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]); die; } try { $request_people = R::getAll(' SELECT name AS people_name,' . ' paper_type, ' . ' paper_number ' . ' FROM supportsr.esr_peoplelist' . ' WHERE requestid = :supportsr_request_id' . ' ORDER BY order1', [':supportsr_request_id' => $supportsr_request_id]); } catch (Exception $e) { header('Content-type:text/json;charset=utf-8'); echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]); die; } R::close(); // Return header('Content-type:text/json;charset=utf-8');
} elseif ($item->is_inside == 0) { $inside = '<span class="label label-danger">לא הגיע</span>'; } elseif ($item->is_inside == 4) { $inside = '<span class="label label-warning">pending</span>'; } elseif ($item->is_inside == 6) { $inside = '<span class="label label-info">בפגישה</span>'; } elseif ($item->is_inside == 7) { $inside = '<span class="label label-info blink_me">גש לעמדה</span>'; } else { $inside = '<span class="label label-info" style="background: #dedede!important">סיים</span>'; } $branch = R::getRow('select * from branches where id = "' . $item->branch . '"'); $branches = 1; $position = R::getRow('select * from position where id = "' . $item->position . '"'); $position = $position['name']; $prev_position = R::getRow('select * from branches where id = "' . $item->prev_position . '"'); if ($prev_position) { if ($item->last_stage) { $prev_position = $positions[2]['name']; } else { $prev_position = $positions[1]['name'] . ' ' . $prev_position['title']; } } else { if ($item->is_inside !== 3) { $prev_position = $positions[0]['name']; } else { $prev_position = ''; } } if ($item->prev_position == 999) { $gotBack = '<span class="label label-danger">From Test drive</span>';
public function getRow($sql, $values = array()) { return R::getRow($sql, $values); }
<?php // change_password_action.php include_once "config.php"; if (session_status() == PHP_SESSION_NONE) { session_start(); } $current_user = get_from_session("current_user"); if (is_null($current_user)) { store_in_session("message", "You must login to access this page"); header("Location: index.php"); return; } $current_password = $_POST["current_password"]; $new_password = $_POST["new_password"]; $new_password2 = $_POST["new_password2"]; $data = R::getRow("select * from users where username=? and password=md5(?)", array($current_user["username"], $current_password)); if (count($data) == 0) { store_in_session("message", "Current password incorrect"); } else { if ($new_password != $new_password2) { store_in_session("message", "New passwords dont match"); } else { $sql = "update users set password = md5(?) where username=?"; R::exec($sql, array($new_password, $current_user["username"])); store_in_session("message", "New password successfully updated!"); } } header("Location: change_password.php");
public function testRun() { chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands'); $command = "php zurmocTest.php install {$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} "; $command .= "{$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword} {$this->temporaryDatabasePort} "; $command .= "{$this->superUserPassword} 'http://sampleHost' 'app/index.php' demodata 1"; if (!IS_WINNT) { $command .= ' 2>&1'; } exec($command, $output); $instanceRoot = INSTANCE_ROOT; $perInstanceConfigFile = "{$instanceRoot}/protected/config/perInstanceTest.php"; $debugConfigFile = "{$instanceRoot}/protected/config/debugTest.php"; $perInstanceConfiguration = file_get_contents($perInstanceConfigFile); $debugConfiguration = file_get_contents($debugConfigFile); //Check if config files is updated. $this->assertRegExp('/\\$connectionString = \'mysql:host=' . $this->temporaryDatabaseHostname . ';port=' . $this->temporaryDatabasePort . ';dbname=' . $this->temporaryDatabaseName . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$username = \'' . $this->temporaryDatabaseUsername . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$password = \'' . $this->temporaryDatabasePassword . '\';/', $perInstanceConfiguration); RedBeanDatabase::close(); RedBeanDatabase::setup(Yii::app()->tempDb->connectionString, Yii::app()->tempDb->username, Yii::app()->tempDb->password, true); $count = R::getRow('select count(*) count from _user'); $this->assertEquals(9, $count['count']); }
/** * @param User $user * @param string $levelType * @return array */ public static function getSummationPointsDataByLevelTypeAndUser(User $user, $levelType) { assert('$user->id > 0'); assert('is_string($levelType) && $levelType != null'); $wherePart = static::getPointTypeWherePartByLevelType($levelType); $sql = "select sum(value) sum from gamepoint where " . $wherePart . " person_item_id = " . $user->getClassId('Item') . " group by person_item_id"; return R::getRow($sql); }
/** * Get the first row of a table. if no rows exist, an NoRowsInTableException is thrown. * @param string $tableName */ public static function getFirstRowByTableName($tableName) { assert('is_string($tableName)'); $sql = 'select * from ' . $tableName; try { $data = R::getRow($sql); } catch (RedBean_Exception_SQL $e) { throw new NoRowsInTableException(); } return $data; }
<?php include_once "header.php"; include_once "config.php"; include_once "menu.php"; $id = $_REQUEST["id"]; $sql = "select * from users where id = ?"; $user = R::getRow($sql, array($id)); $sql = "select typename from usertypes where id=?"; $usertype = R::getCell($sql, array($user["usertype"])); $profile_picture = $user["profile_picture"]; if ($profile_picture == null) { $profile_picture = "./images/profile/default.jpg"; } else { $profile_picture = "./images/profile/default.jpg"; if ($user["profile_picture"] != null) { $ext = substr(strtolower($user["profile_picture"]), -4); if ($ext == ".jpg" || $ext == ".bmp" || $ext == ".gif" || $ext == ".png") { $profile_picture = $user["profile_picture"]; } } } ?> <style type="text/css"> .serviceitem { width: 250px; display: inline-block; margin: 3px; padding: 3px; }
<?php require_once 'functions.php'; if ($_POST['name'] && $_POST['email'] && $_POST['phone']) { $item = R::dispense('users'); $exist = R::getRow('select id from users where email = "' . $_POST['email'] . '"'); if ($exist['id'] > 0) { $the_time = R::getRow('select the_time from testsstarted where user = "******" and test = ' . $_POST['test'] . ' order by the_time DESC LIMIT 1'); $difference = strtotime('now') - $the_time['the_time']; if ($difference > $config['timeForNextTry']) { echo $difference; $tests_started = R::dispense('testsstarted'); $tests_started->user = $exist['id']; $tests_started->test = $_POST['test']; $tests_startedId = R::store($tests_started); } else { echo 'tried'; die('tried'); } } else { $item->name = $_POST['name']; $item->phone = $_POST['phone']; $item->email = $_POST['email']; $id = R::store($item); $tests_started = R::dispense('testsstarted'); $tests_started->user = $id; $tests_started->test = $_POST['test']; $tests_startedId = R::store($tests_started); echo 'new'; } } else {
$results = $_REQUEST['results']; $score_table = '<table width="100%" border="1" cellspacing="0" cellpadding="0">'; $score_table .= '<tr><th style="text-align:center; padding: 5px;"><strong>ID</strong></th><th style="text-align:center; padding: 5px;"><strong>Question</strong></th><th style="text-align:center; padding: 5px;"><strong>User\'s Answer</strong></th><th style="text-align:right; padding: 5px;"><strong>Score</strong></th></tr>'; $user = R::getRow('select id from users where email = "' . $_REQUEST['userEmail'] . '"'); foreach ($results as $result) { print 'select id from answers where name = "' . html_entity_decode($result['answer']) . '" <br>'; $theAnswer = R::getRow('select id, question from answers where name = \'' . html_entity_decode($result['answer']) . '\''); if ($theAnswer['id'] > 0) { } else { $theAnswer = R::getRow('select id, question from answers where name = "' . html_entity_decode($result['answer']) . '"'); } $answer = R::dispense('useranswers'); $answer->user = $user['id']; $answer->question = $theAnswer['question']; $answer->answer = $theAnswer['id']; $answer->points = $result['score']; $answer->test = $_REQUEST['test']; $id = R::store($answer); } $item = R::dispense('results'); $item->user = $user['id']; $item->points = $_REQUEST['user_score']; $item->test = $_REQUEST['test']; $item->total = $_REQUEST['total']; $id = R::store($item); $lastStarted = R::getRow('select id from testsstarted where user = "******" and test = ' . $_REQUEST['test'] . ' order by the_time DESC LIMIT 1'); $tests_started = R::load('testsstarted', $lastStarted['id']); $tests_started->user = $user['id']; $tests_started->test = $_REQUEST['test']; $tests_started->time_end = date("Y-m-d H:i:s", time()); $tests_startedId = R::store($tests_started);
public function getConsumerFavoriteCount($ConsumerId) { try { $OrderCount = R::getRow('SELECT COUNT(id) AS totalCount FROM consumerfavoriteproduct WHERE consumerid=?', [$ConsumerId]); echo ResponseJsonHandler::normalizeJsonResponse($OrderCount); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
include_once '../helper/log_helper.php'; $sync_file_name = "db_log.js"; $sync_function_name = "sync_complete()"; if (isset($_GET) && count($_GET) > 0) { // 查詢模式 // http://localhost/voc4fun/voc4fun-server/model/sync.php?uuid=1×tamp=1448797722000 if (isset($_GET["uuid"]) && isset($_GET["timestamp"])) { $uuid = $_GET["uuid"]; $device_timestamp = floatval($_GET["timestamp"]); } else { exit; } $log = R::getRow('SELECT file_name, function_name, timestamp FROM log ' . 'WHERE uuid = ? AND timestamp > ' . $device_timestamp . ' LIMIT 1 ', [$uuid]); if (count($log) === 0) { // push 模式 part 1: 送出server上最新的timestamp,等待手機回傳資料 $log = R::getRow('SELECT timestamp FROM log WHERE uuid = ? AND timestamp IS NOT NULL ' . 'ORDER BY timestamp DESC LIMIT 1', [$uuid]); if (count($log) > 0) { $timestamp = $log["timestamp"]; $timestamp = floatval($timestamp); //print_r($log); if ($device_timestamp === $timestamp) { $timestamp = true; } jsonp_callback($timestamp); } else { jsonp_callback(0); } exit; } else { // pull 模式: 直接回傳所有資料 if (count($log) > 1 && isset($log[0])) {
<?php include_once "config.php"; header("Content-type: application/json"); $cellphone = $_REQUEST["cellphone"]; $sql = <<<EOT select count(*) as count from users where ? in (cellphone, another_cellphone, landline, another_landline) EOT; $data = R::getRow($sql, array($cellphone)); $out = array("status" => true); if ($data["count"] != 0) { $out = array("status" => false); } echo json_encode($out);