diff --git a/code/web/private_php/ams/autoload/.plugincache.php.swp b/code/web/private_php/ams/autoload/.plugincache.php.swp new file mode 100644 index 000000000..4993b302e Binary files /dev/null and b/code/web/private_php/ams/autoload/.plugincache.php.swp differ diff --git a/code/web/private_php/ams/autoload/assigned.php b/code/web/private_php/ams/autoload/assigned.php index 8de17a9e2..d9d730c8e 100644 --- a/code/web/private_php/ams/autoload/assigned.php +++ b/code/web/private_php/ams/autoload/assigned.php @@ -80,9 +80,9 @@ class Assigned{ $dbl = new DBLayer("lib"); //check if ticket is already assigned - if($user_id == 0 && $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + if($user_id == 0 && $dbl->select("`assigned`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; - }else if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id and `User` = :user_id", array('ticket_id' => $ticket_id, 'user_id' => $user_id) )->rowCount()){ + }else if( $dbl->select("`assigned`", array('ticket_id' => $ticket_id, 'user_id' => $user_id), "`Ticket` = :ticket_id and `User` = :user_id")->rowCount() ){ return true; }else{ return false; @@ -115,9 +115,7 @@ class Assigned{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `assigned` (`User`,`Ticket`) VALUES (:user, :ticket)"; - $values = Array('user' => $this->getUser(), 'ticket' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->insert("`assigned`", Array('User' => $this->getUser(), 'Ticket' => $this->getTicket()); } @@ -127,9 +125,7 @@ class Assigned{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `assigned` WHERE `User` = :user_id and `Ticket` = :ticket_id"; - $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->delete("`assigned`", array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket(), "`User` = :user_id and `Ticket` = :ticket_id"); } /** @@ -139,7 +135,7 @@ class Assigned{ */ public function load($ticket_id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", Array('ticket_id' => $ticket_id)); + $statement = $dbl->select("`assigned`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id"); $row = $statement->fetch(); $this->set($row); } @@ -181,4 +177,4 @@ class Assigned{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/dblayer.php b/code/web/private_php/ams/autoload/dblayer.php index 58ea7b80e..43282789e 100644 --- a/code/web/private_php/ams/autoload/dblayer.php +++ b/code/web/private_php/ams/autoload/dblayer.php @@ -1,85 +1,245 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC - ); - $this->PDO = new PDO($dsn,$cfg['db'][$db]['user'],$cfg['db'][$db]['pass'], $opt); - } else { + $dsn = "mysql:"; + $dsn .= "host=" . $cfg['db'][$db]['host'] . ";"; + $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; + $dsn .= "port=" . $cfg['db'][$db]['port'] . ";"; + + $opt = array( + PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION, + PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_ASSOC + ); + $this -> PDO = new PDO( $dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt ); + } else { global $cfg; - $dsn = "mysql:"; - $dsn .= "host=". $cfg['db'][$dbn]['host'].";"; - $dsn .= "port=". $cfg['db'][$dbn]['port'].";"; + $dsn = "mysql:"; + $dsn .= "host=" . $cfg['db'][$dbn]['host'] . ";"; + $dsn .= "port=" . $cfg['db'][$dbn]['port'] . ";"; + + $opt = array( + PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION, + PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_ASSOC + ); + $this -> PDO = new PDO( $dsn, $_POST['Username'], $_POST['Password'], $opt ); + } - $opt = array( - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC - ); - $this->PDO = new PDO($dsn,$_POST['Username'],$_POST['Password'], $opt); - } - - } + } /** - * execute a query that doesn't have any parameters - * @param $query the mysql query - * @return returns a PDOStatement object - */ - public function executeWithoutParams($query){ - $statement = $this->PDO->prepare($query); - $statement->execute(); - return $statement; - } + * execute a query that doesn't have any parameters + * + * @param $query the mysql query + * @return returns a PDOStatement object + */ + public function executeWithoutParams( $query ) { + $statement = $this -> PDO -> prepare( $query ); + $statement -> execute(); + return $statement; + } /** - * execute a query that has parameters - * @param $query the mysql query - * @param $params the parameters that are being used by the query - * @return returns a PDOStatement object - */ - public function execute($query,$params){ - $statement = $this->PDO->prepare($query); - $statement->execute($params); - return $statement; - } + * execute a query that has parameters + * + * @param $query the mysql query + * @param $params the parameters that are being used by the query + * @return returns a PDOStatement object + */ + public function execute( $query, $params ) { + $statement = $this -> PDO -> prepare( $query ); + $statement -> execute( $params ); + return $statement; + } /** - * execute a query (an insertion query) that has parameters and return the id of it's insertion - * @param $query the mysql query - * @param $params the parameters that are being used by the query - * @return returns the id of the last inserted element. - */ - public function executeReturnId($query,$params){ - $statement = $this->PDO->prepare($query); - $this->PDO->beginTransaction(); - $statement->execute($params); - $lastId =$this->PDO->lastInsertId(); - $this->PDO->commit(); + * execute a query (an insertion query) that has parameters and return the id of it's insertion + * + * @param $query the mysql query + * @param $params the parameters that are being used by the query + * @return returns the id of the last inserted element. + */ + public function executeReturnId( $tb_name, $data ) { + $field_values = ':' . implode( ',:', array_keys( $data ) ); + $field_options = implode( ',', array_keys( $data ) ); + try { + $sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" ); + foreach ( $data as $key => $value ) + { + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + $sth -> execute(); + $lastId = $this -> PDO -> lastInsertId(); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + // for rolling back the changes during transaction + $this -> PDO -> rollBack(); + throw new Exception( "error in inseting" ); + } return $lastId; - } + } + + /** + * Select function using prepared statement + * + * @param string $tb_name Table Name to Select + * @param array $data Associative array + * @param string $where where to select + * @return statement object + */ + public function selectWithParameter( $param, $tb_name, $data, $where ) + { + try { + $sth = $this -> PDO -> prepare( "SELECT $param FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( "error selection" ); + return false; + } + return $sth; + } -} \ No newline at end of file + /** + * Select function using prepared statement + * + * @param string $tb_name Table Name to Select + * @param array $data Associative array + * @param string $where where to select + * @return statement object + */ + public function select( $tb_name, $data , $where ) + { + try { + $sth = $this -> PDO -> prepare( "SELECT * FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( "error selection" ); + return false; + } + return $sth; + } + + /** + * Update function with prepared statement + * + * @param string $tb_name name of the table + * @param array $data associative array with values + * @param string $where where part + * @throws Exception error in updating + */ + public function update( $tb_name, $data, $where ) + { + $field_option_values = null; + foreach ( $data as $key => $value ) + { + $field_option_values .= ",$key" . '=:' . $key; + } + $field_option_values = ltrim( $field_option_values, ',' ); + try { + $sth = $this -> PDO -> prepare( "UPDATE $tb_name SET $field_option_values WHERE $where " ); + + foreach ( $data as $key => $value ) + { + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + $sth -> execute(); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( 'error in updating' ); + return false; + } + return true; + } + + /** + * insert function using prepared statements + * + * @param string $tb_name Name of the table to insert in + * @param array $data Associative array of data to insert + */ + public function insert( $tb_name, $data ) + { + $field_values = ':' . implode( ',:', array_keys( $data ) ); + $field_options = implode( ',', array_keys( $data ) ); + try { + $sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" ); + foreach ( $data as $key => $value ) + { + + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + // execution + $sth -> execute(); + $this -> PDO -> commit(); + + } + catch ( Exception $e ) + { + // for rolling back the changes during transaction + $this -> PDO -> rollBack(); + throw new Exception( "error in inseting" ); + } + } + + /** + * Delete database entery using prepared statement + * + * @param string $tb_name + * @param string $where + * @throws error in deleting + */ + public function delete( $tb_name, $data, $where ) + { + try { + $sth = $this -> PDO -> prepare( "DELETE FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( "error in deleting" ); + } + + } + } diff --git a/code/web/private_php/ams/autoload/forwarded.php b/code/web/private_php/ams/autoload/forwarded.php index 54fece58c..ccba764e6 100644 --- a/code/web/private_php/ams/autoload/forwarded.php +++ b/code/web/private_php/ams/autoload/forwarded.php @@ -55,7 +55,7 @@ class Forwarded{ */ public static function isForwarded( $ticket_id) { $dbl = new DBLayer("lib"); - if( $dbl->execute(" SELECT * FROM `forwarded` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id))->rowCount()){ + if( $dbl->select("`forwarded`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -90,9 +90,7 @@ class Forwarded{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `forwarded` (`Group`,`Ticket`) VALUES (:group, :ticket)"; - $values = Array('group' => $this->getGroup(), 'ticket' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->insert("`forwarded`", Array('Group' => $this->getGroup(), 'Ticket' => $this->getTicket())); } @@ -102,9 +100,7 @@ class Forwarded{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `forwarded` WHERE `Group` = :group_id and `Ticket` = :ticket_id"; - $values = array('group_id' => $this->getGroup() ,'ticket_id' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->delete("`forwarded`", array('group_id' => $this->getGroup() ,'ticket_id' => $this->getTicket(), "`Group` = :group_id and `Ticket` = :ticket_id"); } @@ -115,7 +111,7 @@ class Forwarded{ */ public function load( $ticket_id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `forwarded` WHERE `Ticket` = :ticket_id", Array('ticket_id' => $ticket_id)); + $statement = $dbl->select("`forwarded`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id"); $row = $statement->fetch(); $this->set($row); } @@ -156,4 +152,4 @@ class Forwarded{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/helpers.php b/code/web/private_php/ams/autoload/helpers.php index 8f99bfc93..0ac440800 100644 --- a/code/web/private_php/ams/autoload/helpers.php +++ b/code/web/private_php/ams/autoload/helpers.php @@ -1,229 +1,246 @@ setCompileDir($SITEBASE.'/templates_c/'); - $smarty->setCacheDir($SITEBASE.'/cache/'); - $smarty -> setConfigDir($SITEBASE . '/configs/' ); + $smarty -> setCompileDir( $SITEBASE . '/templates_c/' ); + $smarty -> setCacheDir( $SITEBASE . '/cache/' ); + $smarty -> setConfigDir( $SITEBASE . '/configs/' ); // turn smarty debugging on/off - $smarty -> debugging = false; + $smarty -> debugging = false; // caching must be disabled for multi-language support - $smarty -> caching = false; + $smarty -> caching = false; $smarty -> cache_lifetime = 5; - - //needed by smarty. - helpers :: create_folders (); - global $FORCE_INGAME; - - //if ingame, then use the ingame templates - if ( helpers::check_if_game_client() or $FORCE_INGAME ){ - $smarty -> template_dir = $AMS_LIB . '/ingame_templates/'; + + // needed by smarty. + helpers :: create_folders (); + global $FORCE_INGAME; + + // if ingame, then use the ingame templates + if ( helpers :: check_if_game_client() or $FORCE_INGAME ) { + $smarty -> template_dir = $AMS_LIB . '/ingame_templates/'; $smarty -> setConfigDir( $AMS_LIB . '/configs' ); $variables = parse_ini_file( $AMS_LIB . '/configs/ingame_layout.ini', true ); - foreach ( $variables[$INGAME_LAYOUT] as $key => $value ){ - $smarty -> assign( $key, $value ); - } - }else{ - $smarty -> template_dir = $SITEBASE . '/templates/'; + foreach ( $variables[$INGAME_LAYOUT] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + } else { + $smarty -> template_dir = $SITEBASE . '/templates/'; $smarty -> setConfigDir( $SITEBASE . '/configs' ); - } - - foreach ( $vars as $key => $value ){ - $smarty -> assign( $key, $value ); - } - - //load page specific variables that are language dependent - $variables = Helpers::handle_language(); - foreach ( $variables[$template] as $key => $value ){ - $smarty -> assign( $key, $value ); - } - + } + + foreach ( $vars as $key => $value ) { + $smarty -> assign( $key, $value ); + } + + // load page specific variables that are language dependent + $variables = Helpers :: handle_language(); + if ( $template != 'layout_plugin' ) + { + foreach ( $variables[$template] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + } + // load ams content variables that are language dependent + foreach ( $variables['ams_content'] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + //load ams content variables that are language dependent foreach ( $variables['ams_content'] as $key => $value){ $smarty -> assign( $key, $value); } - //smarty inheritance for loading the matching wrapper layout (with the matching menu bar) - if( isset($vars['permission']) && $vars['permission'] == 3 ){ - $inherited = "extends:layout_admin.tpl|"; - }else if( isset($vars['permission']) && $vars['permission'] == 2){ - $inherited = "extends:layout_mod.tpl|"; - }else if( isset($vars['permission']) && $vars['permission'] == 1){ - $inherited = "extends:layout_user.tpl|"; - }else{ - $inherited =""; - } - - //if $returnHTML is set to true, return the html by fetching the template else display the template. - if($returnHTML == true){ - return $smarty ->fetch($inherited . $template . '.tpl' ); - }else{ - $smarty -> display( $inherited . $template . '.tpl' ); - } - } - - - /** - * creates the folders that are needed for smarty. - * @todo for the drupal module it might be possible that drupal_mkdir needs to be used instead of mkdir, also this should be in the install.php instead. - */ - static public function create_folders(){ - global $AMS_LIB; + // smarty inheritance for loading the matching wrapper layout (with the matching menu bar) + if ( isset( $vars['permission'] ) && $vars['permission'] == 3 ) { + $inherited = "extends:layout_admin.tpl|"; + } else if ( isset( $vars['permission'] ) && $vars['permission'] == 2 ) { + $inherited = "extends:layout_mod.tpl|"; + } else if ( isset( $vars['permission'] ) && $vars['permission'] == 1 ) { + $inherited = "extends:layout_user.tpl|"; + } else { + $inherited = ""; + } + + // if $returnHTML is set to true, return the html by fetching the template else display the template. + if ( $returnHTML == true ) { + return $smarty -> fetch( $inherited . $template . '.tpl' ); + } else { + $smarty -> display( $inherited . $template . '.tpl' ); + } + } + + + /** + * creates the folders that are needed for smarty. + * + * @todo for the drupal module it might be possible that drupal_mkdir needs to be used instead of mkdir, also this should be in the install.php instead. + */ + static public function create_folders() { + global $AMS_LIB; global $SITEBASE; $arr = array( $AMS_LIB . '/ingame_templates/', $AMS_LIB . '/configs', - //$AMS_LIB . '/cache', - $SITEBASE . '/cache/', + // $AMS_LIB . '/cache', + $SITEBASE . '/cache/', $SITEBASE . '/templates/', $SITEBASE . '/templates_c/', $SITEBASE . '/configs' ); - foreach ( $arr as & $value ){ - - if ( !file_exists( $value ) ){ - print($value); - mkdir($value); - } - } - - } - - - /** + foreach ( $arr as &$value ) { + + if ( !file_exists( $value ) ) { + print( $value ); + mkdir( $value ); + } + } + + } + + + /** * check if the http request is sent ingame or not. + * * @return returns true in case it's sent ingame, else false is returned. */ - static public function check_if_game_client() - { - // if HTTP_USER_AGENT is not set then its ryzom core - global $FORCE_INGAME; - if ( ( isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'],"Ryzom") === 0)) || $FORCE_INGAME || ! isset($_SERVER['HTTP_USER_AGENT']) ){ - return true; - }else{ - return false; - } - } - - - /** + static public function check_if_game_client() + { + // if HTTP_USER_AGENT is not set then its ryzom core + global $FORCE_INGAME; + if ( ( isset( $_SERVER['HTTP_USER_AGENT'] ) && ( strpos( $_SERVER['HTTP_USER_AGENT'], "Ryzom" ) === 0 ) ) || $FORCE_INGAME || ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { + return true; + } else { + return false; + } + } + + + /** * Handles the language specific aspect. * The language can be changed by setting the $_GET['Language'] & $_GET['setLang'] together. This will also change the language entry of the user in the db. * Cookies are also being used in case the user isn't logged in. + * * @return returns the parsed content of the language .ini file related to the users language setting. */ - static public function handle_language(){ - global $DEFAULT_LANGUAGE; - global $AMS_TRANS; - - //if user wants to change the language - if(isset($_GET['Language']) && isset($_GET['setLang'])){ - //The ingame client sometimes sends full words, derive those! - switch($_GET['Language']){ - - case "English": - $lang = "en"; - break; - - case "French": - $lang = "fr"; - break; - - default: - $lang = $_GET['Language']; - } - //if the file exists en the setLang = true - if( file_exists( $AMS_TRANS . '/' . $lang . '.ini' ) && $_GET['setLang'] == "true"){ - //set a cookie & session var and incase logged in write it to the db! - setcookie( 'Language', $lang , time() + 60*60*24*30 ); - $_SESSION['Language'] = $lang; - if(WebUsers::isLoggedIn()){ - WebUsers::setLanguage($_SESSION['id'],$lang); - } - }else{ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - }else{ - //if the session var is not set yet - if(!isset($_SESSION['Language'])){ - //check if a cookie already exists for it - if ( isset( $_COOKIE['Language'] ) ) { - $_SESSION['Language'] = $_COOKIE['Language']; - //else use the default language - }else{ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - } - } - - if ($_SESSION['Language'] == ""){ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - return parse_ini_file( $AMS_TRANS . '/' . $_SESSION['Language'] . '.ini', true ); - - } - + static public function handle_language() { + global $DEFAULT_LANGUAGE; + global $AMS_TRANS; + + // if user wants to change the language + if ( isset( $_GET['Language'] ) && isset( $_GET['setLang'] ) ) { + // The ingame client sometimes sends full words, derive those! + switch ( $_GET['Language'] ) { + + case "English": + $lang = "en"; + break; + + case "French": + $lang = "fr"; + break; + + default: + $lang = $_GET['Language']; + } + // if the file exists en the setLang = true + if ( file_exists( $AMS_TRANS . '/' . $lang . '.ini' ) && $_GET['setLang'] == "true" ) { + // set a cookie & session var and incase logged in write it to the db! + setcookie( 'Language', $lang , time() + 60 * 60 * 24 * 30 ); + $_SESSION['Language'] = $lang; + if ( WebUsers :: isLoggedIn() ) { + WebUsers :: setLanguage( $_SESSION['id'], $lang ); + } + } else { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } + } else { + // if the session var is not set yet + if ( !isset( $_SESSION['Language'] ) ) { + // check if a cookie already exists for it + if ( isset( $_COOKIE['Language'] ) ) { + $_SESSION['Language'] = $_COOKIE['Language']; + // else use the default language + } else { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } + } + } - /** - * Time output function for handling the time display. - * @return returns the time in the format specified in the $TIME_FORMAT global variable. - */ - static public function outputTime($time, $str = 1){ - global $TIME_FORMAT; - if($str){ - return date($TIME_FORMAT,strtotime($time)); - }else{ - return date($TIME_FORMAT,$time); - } - } - - /** - * Auto login function for ingame use. - * This function will allow users who access the website ingame, to log in without entering the username and password. It uses the COOKIE entry in the open_ring db. - * it checks if the cookie sent by the http request matches the one in the db. This cookie in the db is changed everytime the user relogs. - * @return returns "FALSE" if the cookies didn't match, else it returns an array with the user's id and name. - */ - static public function check_login_ingame(){ - if ( helpers :: check_if_game_client () or $forcelibrender = false ){ - $dbr = new DBLayer("ring"); - if (isset($_GET['UserId']) && isset($_COOKIE['ryzomId'])){ - $id = $_GET['UserId']; - $statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId'])); - if ($statement->rowCount() ){ - $entry = $statement->fetch(); - //print_r($entry); - return array('id' => $entry['user_id'], 'name' => $entry['user_name']); - }else{ - return "FALSE"; - } - }else{ - return "FALSE"; - } - }else{ - return "FALSE"; - } - } +if ( $_SESSION['Language'] == "" ) { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } +return parse_ini_file( $AMS_TRANS . '/' . $_SESSION['Language'] . '.ini', true ); + + } + + +/** + * Time output function for handling the time display. + * + * @return returns the time in the format specified in the $TIME_FORMAT global variable. + */ +static public function outputTime( $time, $str = 1 ) { +global $TIME_FORMAT; + if ( $str ) { + return date( $TIME_FORMAT, strtotime( $time ) ); + } else { + return date( $TIME_FORMAT, $time ); + } +} + +/** + * Auto login function for ingame use. + * This function will allow users who access the website ingame, to log in without entering the username and password. It uses the COOKIE entry in the open_ring db. + * it checks if the cookie sent by the http request matches the one in the db. This cookie in the db is changed everytime the user relogs. + * + * @return returns "FALSE" if the cookies didn't match, else it returns an array with the user's id and name. + */ +static public function check_login_ingame() { +if ( helpers :: check_if_game_client () or $forcelibrender = false ) { + $dbr = new DBLayer( "ring" ); + if ( isset( $_GET['UserId'] ) && isset( $_COOKIE['ryzomId'] ) ) { + $id = $_GET['UserId']; + + $statement = $dbr -> select( "ring_users", array( 'id' => $id, 'cookie' => $_COOKIE['ryzomId'] ), "user_id=:id AND cookie =:cookie" ); + + // $statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId'])); + + if ( $statement -> rowCount() ) { + $entry = $statement -> fetch(); + // print_r($entry); + return array( 'id' => $entry['user_id'], 'name' => $entry['user_name'] ); + } else { + return "FALSE"; + } + } else { + return "FALSE"; + } + } else { + return "FALSE"; + } +} } diff --git a/code/web/private_php/ams/autoload/in_support_group.php b/code/web/private_php/ams/autoload/in_support_group.php index bf10d3d9a..86c678cd3 100644 --- a/code/web/private_php/ams/autoload/in_support_group.php +++ b/code/web/private_php/ams/autoload/in_support_group.php @@ -21,7 +21,7 @@ class In_Support_Group{ public static function userExistsInSGroup( $user_id, $group_id) { $dbl = new DBLayer("lib"); //check if name is already used - if( $dbl->execute(" SELECT * FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id ", array('user_id' => $user_id, 'group_id' => $group_id) )->rowCount() ){ + if( $dbl->select("in_support_group", array('user_id' => $user_id, 'group_id' => $group_id), "`User` = :user_id and `Group` = :group_id")->rowCount() ){ return true; }else{ return false; @@ -54,9 +54,7 @@ class In_Support_Group{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `in_support_group` (`User`,`Group`) VALUES (:user, :group)"; - $values = Array('user' => $this->user, 'group' => $this->group); - $dbl->execute($query, $values); + $dbl->insert("`in_support_group`", Array('User' => $this->user, 'Group' => $this->group); } @@ -66,9 +64,7 @@ class In_Support_Group{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id"; - $values = array('user_id' => $this->getUser() ,'group_id' => $this->getGroup()); - $dbl->execute($query, $values); + $dbl->delete("`in_support_group`", array('user_id' => $this->getUser() ,'group_id' => $this->getGroup(), "`User` = :user_id and `Group` = :group_id"); } /* @@ -118,4 +114,4 @@ class In_Support_Group{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/mail_handler.php b/code/web/private_php/ams/autoload/mail_handler.php index dde8d4e02..66cb0f95d 100644 --- a/code/web/private_php/ams/autoload/mail_handler.php +++ b/code/web/private_php/ams/autoload/mail_handler.php @@ -118,12 +118,7 @@ class Mail_Handler{ $id_user = $recipient; $recipient = NULL; } - - $query = "INSERT INTO email (Recipient,Subject,Body,Status,Attempts,Sender,UserId,MessageId,TicketId) VALUES (:recipient, :subject, :body, :status, :attempts, :sender, :id_user, :messageId, :ticketId)"; - $values = array('recipient' => $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'attempts'=> 0, 'sender' => $from,'id_user' => $id_user, 'messageId' => 0, 'ticketId'=> $ticket_id); - $db = new DBLayer("lib"); - $db->execute($query, $values); - + $db->insert("email", array('Recipient' => $recipient, 'Subject' => $subject, 'Body' => $body, 'Status' => 'NEW', 'Attempts'=> 0, 'Sender' => $from,'UserId' => $id_user, 'MessageId' => 0, 'TicketId'=> $ticket_id)); } @@ -173,7 +168,7 @@ class Mail_Handler{ //select all new & failed emails & try to send them //$emails = db_query("select * from email where status = 'NEW' or status = 'FAILED'"); - $statement = $this->db->executeWithoutParams("select * from email where Status = 'NEW' or Status = 'FAILED'"); + $statement = $this->db->select("email",array(null), "Status = 'NEW' or Status = 'FAILED'"); $emails = $statement->fetchAll(); foreach($emails as $email) { diff --git a/code/web/private_php/ams/autoload/plugincache.php b/code/web/private_php/ams/autoload/plugincache.php new file mode 100644 index 000000000..c90665bc1 --- /dev/null +++ b/code/web/private_php/ams/autoload/plugincache.php @@ -0,0 +1,269 @@ + setId( $values['Id'] ); + $this -> setPluginName( $values['Name'] ); + $this -> setPluginType( $values['Type'] ); + $this -> setPluginPermission( $values['Permission'] ); + $this -> setPluginStatus( $values['Status'] ); + $this -> setPluginInfo( json_decode( $values['Info'] ) ); + @$this -> setUpdateInfo( json_decode( $values['UpdateInfo'] ) ); + } + + /** + * loads the object's attributes. + */ + + public function load_With_SID() { + $dbl = new DBLayer( "lib" ); + $statement = $dbl -> executeWithoutParams( "SELECT * FROM plugins" ); + $row = $statement -> fetch(); + $this -> set( $row ); + } + + /** + * get plugin id attribute of the object. + * + * @return integer id + */ + public function getId() { + return $this -> Id; + } + + /** + * get plugin permission attribute of the object. + */ + public function getPluginPermission() { + return $this -> plugin_permission; + } + + /** + * get plugin Type attribute of the object. + */ + public function getPluginType() { + return $this -> plugin_version; + } + + /** + * get plugin status attribute of the object. + */ + public function getPluginStatus() { + return $this -> plugin_status; + } + + /** + * get plugin name attribute of the object. + */ + public function getPluginName() { + return $this -> plugin_name; + } + + /** + * get plugin info array attribute of the object. + */ + public function getPluginInfo() { + return $this -> plugin_info; + } + + /** + * set plugin id attribute of the object. + * + * @param $s integer id + */ + public function setId( $s ) { + $this -> Id = $s; + } + + /** + * set plugin permission attribute of the object. + * + * @param $t type of the query, set permission + */ + public function setPluginPermission( $t ) { + $this -> plugin_permission = $t; + } + + /** + * set plugin version attribute of the object. + * + * @param $q string to set plugin version + */ + public function setPluginType( $q ) { + $this -> plugin_version = $q; + } + + /** + * set plugin status attribute of the object. + * + * @param $d status code type int + */ + public function setPluginStatus( $d ) { + $this -> plugin_status = $d; + } + + /** + * set plugin name attribute of the object. + * + * @param $p_n string to set plugin name. + */ + public function setPluginName( $p_n ) { + $this -> plugin_name = $p_n; + } + + /** + * set plugin info attribute array of the object. + * + * @param $p_n array + */ + public function setPluginInfo( $p_n ) { + $this -> plugin_info = $p_n; + } + + /** + * functionalities for plugin updates + */ + + /** + * set update info attribute array of the object. + * + * @param $p_n array + */ + public function setUpdateInfo( $p_n ) { + $this -> update_info = $p_n; + } + + /** + * get plugin info array attribute of the object. + */ + public function getUpdateInfo() { + return $this -> update_info; + } + + /** + * some more plugin function that requires during plugin operations + */ + + /** + * function to remove a non empty directory + * + * @param $dir directory address + * @return boolean + */ + public static function rrmdir( $dir ) { + $result = array_diff( scandir( $dir ), array( '.', '..' ) ); + foreach( $result as $item ) + { + if ( !@unlink( $dir . '/' . $item ) ) + Plugincache :: rrmdir( $dir . '/' . $item ); + } + return rmdir( $dir ); + } + + /** + * function to unzip the zipped files + * + * @param $target_path path to the target zipped file + * @param $destination path to the destination + * @return boolean + */ + public static function zipExtraction( $target_path, $destination ) + { + $zip = new ZipArchive(); + $x = $zip -> open( $target_path ); + if ( $x === true ) { + if ( $zip -> extractTo( $destination ) ) + { + $zip -> close(); + return true; + } + else + { + $zip -> close(); + return false; + } + } + } + + /** + * returns plugin information with respect to the id + * + * @param id $ plugin id + * @return field info for the plugin + */ + public static function pluginInfoUsingId( $id, $fieldName ) + { + $db = new DBLayer( 'lib' ); + $sth = $db -> selectWithParameter( $fieldName, 'plugins', array( 'id' => $id ), 'Id=:id' ); + $row = $sth -> fetch(); + return $row[$fieldName]; + } + + /** + * function provides list of active plugins + * + * @return $ac_plugins list of active plugins + */ + public static function activePlugins() + { + $db = new DBLayer( 'lib' ); + $sth = $db -> selectWithParameter( 'Id', 'plugins', array( 'status' => 1 ), 'Status=:status' ); + $row = $sth -> fetchAll(); + return $row; + } + + /** + * function to load hooks for the active plugins + * and return the contents in the hooks in an array + * + * @return $content content available in hooks + */ + public static function loadHooks() + { + $content = array(); + $ac_arr = Plugincache :: activePlugins(); + foreach( $ac_arr as $key => $value ) + { + $plugin_path = Plugincache :: pluginInfoUsingId( $value['Id'], 'FileName' ); + $template_path = json_decode( Plugincache :: pluginInfoUsingId( $value['Id'], 'Info' ) ) -> TemplatePath; + $plugin_name = explode( '/', $plugin_path )[4]; + + // calling hooks in the $pluginName.php + include $plugin_path . '/' . $plugin_name . '.php'; + $arr = get_defined_functions(); + + foreach( $arr['user'] as $key => $value ) + { + if ( stristr( $value, $plugin_name ) == true ) + { + $content['hook_info'][$plugin_name] = call_user_func( $value ); + } + } + // path for the template + $content['hook_info'][$plugin_name]['TemplatePath'] = $template_path; + } + + return $content; + } + } diff --git a/code/web/private_php/ams/autoload/querycache.php b/code/web/private_php/ams/autoload/querycache.php index 3da0887c9..6f0c0dca6 100644 --- a/code/web/private_php/ams/autoload/querycache.php +++ b/code/web/private_php/ams/autoload/querycache.php @@ -47,7 +47,7 @@ class Querycache{ */ public function load_With_SID( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ams_querycache WHERE SID=:id", array('id' => $id)); + $statement = $dbl->select("ams_querycache", array('id' => $id), "SID=:id"); $row = $statement->fetch(); $this->set($row); } @@ -58,9 +58,7 @@ class Querycache{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ams_querycache SET type= :t, query = :q, db = :d WHERE SID=:id"; - $values = Array('id' => $this->getSID(), 't' => $this->getType(), 'q' => $this->getQuery(), 'd' => $this->getDb()); - $statement = $dbl->execute($query, $values); + $dbl->update("ams_querycache", Array('type' => $this->getType(), 'query' => $this->getQuery(), 'db' => $this->getDb(), "SID=$this->getSID()" ); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -127,4 +125,4 @@ class Querycache{ $this->db= $d; } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/rest_api.php b/code/web/private_php/ams/autoload/rest_api.php new file mode 100644 index 000000000..74281c6f6 --- /dev/null +++ b/code/web/private_php/ams/autoload/rest_api.php @@ -0,0 +1,72 @@ +execute("SELECT * FROM support_group WHERE SGroupId = :id", array('id' => $id)); + $statement = $dbl->select("support_group", array('id' => $id), "SGroupId = :id"); $row = $statement->fetch(); $instanceGroup = new self(); $instanceGroup->set($row); @@ -102,10 +102,10 @@ class Support_Group{ public static function supportGroup_EntryNotExists( $name, $tag) { $dbl = new DBLayer("lib"); //check if name is already used - if( $dbl->execute("SELECT * FROM support_group WHERE Name = :name",array('name' => $name))->rowCount() ){ + if( $dbl->select("support_group", array('name' => $name), "Name = :name")->rowCount() ){ return "NAME_TAKEN"; } - else if( $dbl->execute("SELECT * FROM support_group WHERE Tag = :tag",array('tag' => $tag))->rowCount() ){ + else if( $dbl->select("support_group", array('tag' => $tag), "Tag = :tag")->rowCount() ){ return "TAG_TAKEN"; }else{ return "SUCCESS"; @@ -121,7 +121,7 @@ class Support_Group{ public static function supportGroup_Exists( $id) { $dbl = new DBLayer("lib"); //check if supportgroup id exist - if( $dbl->execute("SELECT * FROM support_group WHERE SGroupId = :id",array('id' => $id ))->rowCount() ){ + if( $dbl->select("support_group", array('id' => $id ), "SGroupId = :id")->rowCount() ){ return true; }else{ return false; @@ -305,9 +305,7 @@ class Support_Group{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO support_group (Name, Tag, GroupEmail, IMAP_MailServer, IMAP_Username, IMAP_Password) VALUES (:name, :tag, :groupemail, :imap_mailserver, :imap_username, :imap_password)"; - $values = Array('name' => $this->getName(), 'tag' => $this->getTag(), 'groupemail' => $this->getGroupEmail(), 'imap_mailserver' => $this->getIMAP_MailServer(), 'imap_username' => $this->getIMAP_Username(), 'imap_password' => $this->getIMAP_Password()); - $dbl->execute($query, $values); + $dbl->insert("support_group", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_Password' => $this->getIMAP_Password())); } @@ -318,7 +316,7 @@ class Support_Group{ */ public function load_With_SGroupId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `support_group` WHERE `SGroupId` = :id", array('id' => $id)); + $statement = $dbl->select("`support_group`", array('id' => $id), "`SGroupId` = :id"); $row = $statement->fetch(); $this->set($row); } @@ -329,9 +327,7 @@ class Support_Group{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE `support_group` SET `Name` = :name, `Tag` = :tag, `GroupEmail` = :groupemail, `IMAP_MailServer` = :mailserver, `IMAP_Username` = :username, `IMAP_Password` = :password WHERE `SGroupId` = :id"; - $values = Array('id' => $this->getSGroupId(), 'name' => $this->getName(), 'tag' => $this->getTag(), 'groupemail' => $this->getGroupEmail(), 'mailserver' => $this->getIMAP_MailServer(), 'username' => $this->getIMAP_Username(), 'password' => $this->getIMAP_Password() ); - $statement = $dbl->execute($query, $values); + $dbl->update("`support_group`", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_password' => $this->getIMAP_Password(), "`SGroupId` = $this->getSGroupId()")); } @@ -341,9 +337,7 @@ class Support_Group{ */ public function delete(){ $dbl = new DBLayer("lib"); - $query = "DELETE FROM `support_group` WHERE `SGroupId` = :id"; - $values = Array('id' => $this->getSGroupId()); - $statement = $dbl->execute($query, $values); + $dbl->delete("`support_group`", Array('id' => $this->getSGroupId(), "`SGroupId` = :id")); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -453,4 +447,4 @@ class Support_Group{ public function setIMAP_Password($p){ $this->iMap_Password = $p; } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/sync.php b/code/web/private_php/ams/autoload/sync.php index e9d4c8748..a79ef8b83 100644 --- a/code/web/private_php/ams/autoload/sync.php +++ b/code/web/private_php/ams/autoload/sync.php @@ -42,34 +42,37 @@ class Sync{ $decode = json_decode($record['query']); $values = array('username' => $decode[0]); //make connection with and put into shard db & delete from the lib - $sth = $db->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $sth=$db->selectWithParameter("UId", "user", $values, "Login= :username" ); $result = $sth->fetchAll(); foreach ($result as $UId) { - $ins_values = array('id' => $UId['UId']); - $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); - $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + $ins_values = array('UId' => $UId['UId']); + $ins_values['ClientApplication'] = "r2"; + $ins_values['AccessPrivilege'] = "OPEN"; + $db->insert("permission", $ins_values); + $ins_values['ClientApplication'] = 'ryzom_open'; + $db->insert("permission",$ins_values); } break; case 'change_pass': $decode = json_decode($record['query']); - $values = array('user' => $decode[0], 'pass' => $decode[1]); + $values = array('Password' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); + $db->update("user", $values, "Login = $decode[0]"); break; case 'change_mail': $decode = json_decode($record['query']); - $values = array('user' => $decode[0], 'mail' => $decode[1]); + $values = array('Email' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); + $db->update("user", $values, "Login = $decode[0]"); break; case 'createUser': $decode = json_decode($record['query']); - $values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] ); + $values = array('Login' => $decode[0], 'Password' => $decode[1], 'Email' => $decode[2] ); //make connection with and put into shard db & delete from the lib - $db->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values); + $db->insert("user", $values); break; } - $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); + $dbl->delete("ams_querycache", array('SID' => $record['SID']), "SID=:SID"); } if ($display == true) { print('Syncing completed'); diff --git a/code/web/private_php/ams/autoload/ticket.php b/code/web/private_php/ams/autoload/ticket.php index 21e2614d5..51f987e5a 100644 --- a/code/web/private_php/ams/autoload/ticket.php +++ b/code/web/private_php/ams/autoload/ticket.php @@ -27,7 +27,7 @@ class Ticket{ public static function ticketExists($id) { $dbl = new DBLayer("lib"); //check if ticket exists - if( $dbl->execute(" SELECT * FROM `ticket` WHERE `TId` = :ticket_id", array('ticket_id' => $id) )->rowCount() ){ + if( $dbl->select("`ticket`", array('ticket_id' => $id), "`TId` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -343,9 +343,7 @@ class Ticket{ */ public function create(){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author, Priority) VALUES (now(), :title, :status, :queue, :tcat, :author, :priority)"; - $values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority); - $this->tId = $dbl->executeReturnId($query, $values); ; + $this->tId = $dbl->executeReturnId("ticket", Array('Timestamp'=>now(), 'Title' => $this->title, 'Status' => $this->status, 'Queue' => $this->queue, 'Ticket_Category' => $this->ticket_category, 'Author' => $this->author, 'Priority' => $this->priority)); } @@ -356,7 +354,7 @@ class Ticket{ */ public function load_With_TId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket WHERE TId=:id", array('id' => $id)); + $statement = $dbl->select("ticket", array('id' => $id), "TId=:id"); $row = $statement->fetch(); $this->tId = $row['TId']; $this->timestamp = $row['Timestamp']; @@ -374,9 +372,7 @@ class Ticket{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author, Priority = :priority WHERE TId=:id"; - $values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket", Array('Timestamp' => $this->timestamp, 'Title' => $this->title, 'Status' => $this->status, 'Queue' => $this->queue, 'Ticket_Category' => $this->ticket_category, 'Author' => $this->author, 'Priority' => $this->priority), "TId=$this->tId"); } @@ -575,4 +571,4 @@ class Ticket{ $this->priority = $p; } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_category.php b/code/web/private_php/ams/autoload/ticket_category.php index 92e603d12..f6941febe 100644 --- a/code/web/private_php/ams/autoload/ticket_category.php +++ b/code/web/private_php/ams/autoload/ticket_category.php @@ -16,10 +16,7 @@ class Ticket_Category{ */ public static function createTicketCategory( $name) { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_category (Name) VALUES (:name)"; - $values = Array('name' => $name); - $dbl->execute($query, $values); - + $dbl->insert("ticket_category", Array('Name' => $name)); } @@ -40,7 +37,7 @@ class Ticket_Category{ */ public static function getAllCategories() { $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM ticket_category"); + $statement = $dbl->select("ticket_category", array(null), "1"); $row = $statement->fetchAll(); $result = Array(); foreach($row as $category){ @@ -70,7 +67,7 @@ class Ticket_Category{ */ public function load_With_TCategoryId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_category", array('id' => $id), "TCategoryId=:id"); $row = $statement->fetch(); $this->tCategoryId = $row['TCategoryId']; $this->name = $row['Name']; @@ -82,9 +79,7 @@ class Ticket_Category{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id"; - $values = Array('id' => $this->tCategoryId, 'name' => $this->name); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_category", Array('Name' => $this->name), "TCategoryId = $this->tCategoryId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -126,4 +121,4 @@ class Ticket_Category{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_content.php b/code/web/private_php/ams/autoload/ticket_content.php index 445cad867..8b7787f8e 100644 --- a/code/web/private_php/ams/autoload/ticket_content.php +++ b/code/web/private_php/ams/autoload/ticket_content.php @@ -43,9 +43,7 @@ class Ticket_Content{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_content (Content) VALUES (:content)"; - $values = Array('content' => $this->content); - $this->tContentId = $dbl->executeReturnId($query, $values); ; + $this->tContentId = $dbl->executeReturnId("ticket_content", Array('Content' => $this->content)); } @@ -56,7 +54,7 @@ class Ticket_Content{ */ public function load_With_TContentId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_content WHERE TContentId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_content", array('id' => $id), "TContentId=:id"); $row = $statement->fetch(); $this->tContentId = $row['TContentId']; $this->content = $row['Content']; @@ -67,9 +65,7 @@ class Ticket_Content{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_content SET Content = :content WHERE TContentId=:id"; - $values = Array('id' => $this->tContentId, 'content' => $this->content); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_content", Array('Content' => $this->content), "TContentId = $this->tContentId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -110,4 +106,4 @@ class Ticket_Content{ $this->tContentId = $c; } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_info.php b/code/web/private_php/ams/autoload/ticket_info.php index fc852d093..eb7c8ebc5 100644 --- a/code/web/private_php/ams/autoload/ticket_info.php +++ b/code/web/private_php/ams/autoload/ticket_info.php @@ -52,7 +52,7 @@ class Ticket_Info{ public static function TicketHasInfo($ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is already assigned - if( $dbl->execute(" SELECT * FROM `ticket_info` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + if( $dbl->select("`ticket_info`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -102,7 +102,7 @@ class Ticket_Info{ */ public function load_With_TInfoId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_info WHERE TInfoId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_info", array('id' => $id), "TInfoId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -115,7 +115,7 @@ class Ticket_Info{ */ public function load_With_Ticket( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_info WHERE Ticket=:id", array('id' => $id)); + $statement = $dbl->select("ticket_info", array('id' => $id), "Ticket=:id"); $row = $statement->fetch(); $this->set($row); } @@ -127,12 +127,10 @@ class Ticket_Info{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_info ( Ticket, ShardId, UserPosition,ViewPosition, ClientVersion, PatchVersion,ServerTick, ConnectState, LocalAddress, Memory, OS, -Processor, CPUID, CpuMask, HT, NeL3D, UserId) VALUES ( :ticket, :shardid, :userposition, :viewposition, :clientversion, :patchversion, :servertick, :connectstate, :localaddress, :memory, :os, :processor, :cpuid, :cpu_mask, :ht, :nel3d, :user_id )"; - $values = Array('ticket' => $this->getTicket(), 'shardid' => $this->getShardId(), 'userposition' => $this->getUser_Position(), 'viewposition' => $this->getView_Position(), 'clientversion' => $this->getClient_Version(), -'patchversion' => $this->getPatch_Version(), 'servertick' => $this->getServer_Tick(), 'connectstate' => $this->getConnect_State(), 'localaddress' => $this->getLocal_Address(), 'memory' => $this->getMemory(), 'os'=> $this->getOS(), 'processor' => $this->getProcessor(), 'cpuid' => $this->getCPUId(), -'cpu_mask' => $this->getCpu_Mask(), 'ht' => $this->getHT(), 'nel3d' => $this->getNel3D(), 'user_id' => $this->getUser_Id()); - $dbl->execute($query, $values); + $values = Array('Ticket' => $this->getTicket(), 'ShardId' => $this->getShardId(), 'UserPosition' => $this->getUser_Position(), 'ViewPosition' => $this->getView_Position(), 'ClientVersion' => $this->getClient_Version(), +'PatchVersion' => $this->getPatch_Version(), 'ServerTick' => $this->getServer_Tick(), 'ConnectState' => $this->getConnect_State(), 'LocalAddress' => $this->getLocal_Address(), 'Memory' => $this->getMemory(), 'OS'=> $this->getOS(), 'Processor' => $this->getProcessor(), 'CPUID' => $this->getCPUId(), +'CpuMask' => $this->getCpu_Mask(), 'HT' => $this->getHT(), 'NeL3D' => $this->getNel3D(), 'UserId' => $this->getUser_Id()); + $dbl->insert("ticket_info",$values); } @@ -411,4 +409,4 @@ Processor, CPUID, CpuMask, HT, NeL3D, UserId) VALUES ( :ticket, :shardid, :user } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_log.php b/code/web/private_php/ams/autoload/ticket_log.php index 8c7439bc0..6693fe3ce 100644 --- a/code/web/private_php/ams/autoload/ticket_log.php +++ b/code/web/private_php/ams/autoload/ticket_log.php @@ -82,9 +82,8 @@ class Ticket_Log{ global $TICKET_LOGGING; if($TICKET_LOGGING){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_log (Timestamp, Query, Ticket, Author) VALUES (now(), :query, :ticket, :author )"; - $values = Array('ticket' => $ticket_id, 'author' => $author_id, 'query' => json_encode(array($action,$arg))); - $dbl->execute($query, $values); + $values = Array('Timestamp'=>now(), 'Query' => json_encode(array($action,$arg)), 'Ticket' => $ticket_id, 'Author' => $author_id); + $dbl->insert("ticket_log", $values); } } @@ -148,7 +147,7 @@ class Ticket_Log{ */ public function load_With_TLogId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_log WHERE TLogId=:id", array('id' => $id)); + $dbl->select("ticket_log", array('id' => $id), "TLogId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -159,9 +158,10 @@ class Ticket_Log{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id"; - $values = Array('id' => $this->getTLogId(), 'timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() ); - $statement = $dbl->execute($query, $values); + + $values = Array('timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() ); + $dbl->update("ticket_log", $values, "TLogId = $this->getTLogId()"); + } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -273,4 +273,4 @@ class Ticket_Log{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_reply.php b/code/web/private_php/ams/autoload/ticket_reply.php index 8e784543d..2675fcfbe 100644 --- a/code/web/private_php/ams/autoload/ticket_reply.php +++ b/code/web/private_php/ams/autoload/ticket_reply.php @@ -123,9 +123,7 @@ class Ticket_Reply{ */ public function create(){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp, Hidden) VALUES (:ticket, :content, :author, now(), :hidden)"; - $values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden); - $this->tReplyId = $dbl->executeReturnId($query, $values); + $this->tReplyId = $dbl->executeReturnId("ticket_reply", Array('Ticket' => $this->ticket, 'Content' => $this->content, 'Author' => $this->author,'Timestamp'=>now(), 'Hidden' => $this->hidden)); } /** @@ -135,7 +133,7 @@ class Ticket_Reply{ */ public function load_With_TReplyId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_reply WHERE TReplyId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_reply", array('id' => $id), "TReplyId=:id"); $row = $statement->fetch(); $this->tReplyId = $row['TReplyId']; $this->ticket = $row['Ticket']; @@ -150,9 +148,7 @@ class Ticket_Reply{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp, Hidden = :hidden WHERE TReplyId=:id"; - $values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket", Array('Ticket' => $this->ticket, 'Content' => $this->content, 'Author' => $this->author, 'Timestamp' => $this->timestamp, 'Hidden' => $this->hidden), "TReplyId=$this->tReplyId, "); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -249,4 +245,4 @@ class Ticket_Reply{ public function setHidden($h){ $this->hidden = $h; } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/ticket_user.php b/code/web/private_php/ams/autoload/ticket_user.php index 46125e284..0937b48b0 100644 --- a/code/web/private_php/ams/autoload/ticket_user.php +++ b/code/web/private_php/ams/autoload/ticket_user.php @@ -21,10 +21,7 @@ class Ticket_User{ */ public static function createTicketUser( $extern_id, $permission) { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_user (Permission, ExternId) VALUES (:perm, :ext_id)"; - $values = Array('perm' => $permission, 'ext_id' => $extern_id); - $dbl->execute($query, $values); - + $dbl->insert("ticket_user",array('Permission' => $permission, 'ExternId' => $extern_id)); } @@ -73,7 +70,7 @@ class Ticket_User{ */ public static function getModsAndAdmins() { $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM `ticket_user` WHERE `Permission` > 1"); + $statement = $dbl->select("ticket_user", array(null), "`Permission` > 1" ); $rows = $statement->fetchAll(); $result = Array(); foreach($rows as $user){ @@ -93,7 +90,7 @@ class Ticket_User{ public static function constr_ExternId( $id) { $instance = new self(); $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_user WHERE ExternId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_user" ,array('id'=>$id) ,"ExternId=:id"); $row = $statement->fetch(); $instance->tUserId = $row['TUserId']; $instance->permission = $row['Permission']; @@ -196,7 +193,7 @@ class Ticket_User{ */ public function load_With_TUserId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_user" ,array('id'=>$id), "TUserId=:id" ); $row = $statement->fetch(); $this->tUserId = $row['TUserId']; $this->permission = $row['Permission']; @@ -209,9 +206,7 @@ class Ticket_User{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_user SET Permission = :perm, ExternId = :ext_id WHERE TUserId=:id"; - $values = Array('id' => $this->tUserId, 'perm' => $this->permission, 'ext_id' => $this->externId); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_user" ,array('Permission' => $this->permission, 'ExternId' => $this->externId) ,"TUserId=$this->tUserId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -266,4 +261,4 @@ class Ticket_User{ } -} \ No newline at end of file +} diff --git a/code/web/private_php/ams/autoload/users.php b/code/web/private_php/ams/autoload/users.php index f83f46576..b398270e4 100644 --- a/code/web/private_php/ams/autoload/users.php +++ b/code/web/private_php/ams/autoload/users.php @@ -289,11 +289,13 @@ class Users{ public static function createUser($values, $user_id){ try { //make connection with and put into shard db - $values['user_id']= $user_id; $dbs = new DBLayer("shard"); - $dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values); + $dbs->insert("user", $values); $dbr = new DBLayer("ring"); - $dbr->execute("INSERT INTO ring_users (user_id, user_name, user_type) VALUES (:user_id, :name, 'ut_pioneer')",$values); + $valuesRing['user_id'] =$user_id; + $valuesRing['user_name'] = $values['Login']; + $valuesRing['user_type'] = 'ut_pioneer'; + $dbr->insert("ring_users", $valuesRing); ticket_user::createTicketUser( $user_id, 1); return "ok"; } @@ -301,8 +303,8 @@ class Users{ //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createUser", - "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])), "db" => "shard")); + $dbl->insert("ams_querycache", array("type" => "createUser", + "query" => json_encode(array($values["Login"],$values["Password"],$values["Email"])), "db" => "shard")); ticket_user::createTicketUser( $user_id , 1 ); return "shardoffline"; }catch (PDOException $e) { @@ -323,21 +325,20 @@ class Users{ try { $values = array('username' => $pvalues[0]); $dbs = new DBLayer("shard"); - $sth = $dbs->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $sth = $dbs->selectWithParameter("UId", "user", $values, "Login= :username"); $result = $sth->fetchAll(); foreach ($result as $UId) { - $ins_values = array('id' => $UId['UId']); - $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); - $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + $ins_values = array('UId' => $UId['UId'], 'clientApplication' => 'r2', 'AccessPrivilege' => 'OPEN'); + $dbs->insert("permission", $ins_values); + $ins_values['clientApplication'] = 'ryzom_open'; + $dbs->insert("permission", $ins_values); } } catch (PDOException $e) { //oh noooz, the shard is offline! Put it in query queue at ams_lib db! $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createPermissions", - "query" => json_encode(array($pvalues[0])), "db" => "shard")); - - + $dbl->insert("ams_querycache", array("type" => "createPermissions", + "query" => json_encode(array($pvalues[0])), "db" => "shard")); } return true; } @@ -421,19 +422,19 @@ class Users{ */ protected static function setAmsPassword($user, $pass){ - $values = Array('user' => $user, 'pass' => $pass); + $values = Array('Password' => $pass); try { //make connection with and put into shard db $dbs = new DBLayer("shard"); - $dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user ",$values); + $dbs->update("user", $values, "Login = $user"); return "ok"; } catch (PDOException $e) { //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_pass", + $dbl->insert("ams_querycache", array("type" => "change_pass", "query" => json_encode(array($values["user"],$values["pass"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { @@ -451,19 +452,19 @@ class Users{ */ protected static function setAmsEmail($user, $mail){ - $values = Array('user' => $user, 'mail' => $mail); + $values = Array('Email' => $mail); try { //make connection with and put into shard db $dbs = new DBLayer("shard"); - $dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user ",$values); + $dbs->update("user", $values, "Login = $user"); return "ok"; } catch (PDOException $e) { //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_mail", + $dbl->insert("ams_querycache", array("type" => "change_mail", "query" => json_encode(array($values["user"],$values["mail"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { @@ -472,6 +473,3 @@ class Users{ } } } - - - \ No newline at end of file diff --git a/code/web/private_php/ams/plugins/API_key_management/.info b/code/web/private_php/ams/plugins/API_key_management/.info new file mode 100644 index 000000000..b185a31db --- /dev/null +++ b/code/web/private_php/ams/plugins/API_key_management/.info @@ -0,0 +1,8 @@ +PluginName = API Key Management +Description = Provides public access to the API's by generating access tokens. +Version = 1.0.0 +Type = automatic +TemplatePath = ../../../ams_lib/plugins/API_key_management/templates/index.tpl + + + diff --git a/code/web/private_php/ams/plugins/API_key_management/API_key_management.php b/code/web/private_php/ams/plugins/API_key_management/API_key_management.php new file mode 100644 index 000000000..27613e18b --- /dev/null +++ b/code/web/private_php/ams/plugins/API_key_management/API_key_management.php @@ -0,0 +1,213 @@ + executeWithoutParams( $sql ); + } + +/** + * Hook to store data to database which is sent as post + * method from the forms in this plugin + * It also calls the local hook + */ +function api_key_management_hook_store_db() + { + global $var_set; + global $return_set; + + // if the form been submited move forward + if ( @hook_validate( $_POST['gen_key'] ) ) { + + // local hook to validate the POST variables + hook_variables(); + + // if validation successfull move forward + if ( $return_set['gen_key_validate'] == 'true' && $_GET['plugin_action'] == 'generate_key' ) + { + // this part generated the access token + include 'generate_key.php'; + $var_set['AccessToken'] = generate_key :: randomToken( 56, false, true, false ); + + // database connection + $db = new DBLayer( 'lib' ); + // insert the form data to the database + $db -> insert( 'ams_api_keys', $var_set ); + + // redirect to the the main page with success code + // 1 refers to the successfull addition of key to the database + header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=1" ); + exit; + } + } + } + +/** + * Global Hook to load the data from db and set it + * into the global array to return it to the template + */ +function api_key_management_hook_load_db() + { + global $var_set; + global $return_set; + + $db = new DBLayer( 'lib' ); + + if ( isset( $_SESSION['user'] ) ) + { + // returns the registered keys + $sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' ); + $row = $sth -> fetchAll(); + $return_set['api_keys'] = $row; + + // fetch the character from the array to compare + $com = array_column( $return_set['api_keys'], 'UserCharacter' ); + + // returns the characters with respect to the user id in the ring_tool->characters + $db = new DBLayer( 'ring' ); + $sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' ); + $row = $sth -> fetch(); + + // loop through the character list and remove the character if already have an api key + $return_set['characters'] = array_diff( $row, $com ); + } + } + +/** + * Global Hook to update or delete the data from db + */ +function api_key_management_hook_update_db() + { + global $var_set; + global $return_set; + + $db = new DBLayer( 'lib' ); + if ( isset( $_GET['delete_id'] ) ) + { + // removes the registered key using get variable which contains the id of the registered key + $db -> delete( 'ams_api_keys', array( 'SNo' => $_GET['delete_id'] ), 'SNo = :SNo' ); + + // redirecting to the API_key_management plugins template with success code + // 2 refers to the succssfull delete condition + header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" ); + exit; + } + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates + * + * @return $return_set global array returns the template data + */ +function api_key_management_hook_return_global() + { + global $return_set; + return $return_set; + } diff --git a/code/web/private_php/ams/plugins/API_key_management/generate_key.php b/code/web/private_php/ams/plugins/API_key_management/generate_key.php new file mode 100644 index 000000000..1ddfab7ed --- /dev/null +++ b/code/web/private_php/ams/plugins/API_key_management/generate_key.php @@ -0,0 +1,53 @@ + 2, 2 => 8, 3 => 10, 4 => 16, 5 => 10 ); + if ( !is_array( $chars ) ) { + $chars = array_unique( str_split( $chars ) ); + } + if ( $standardChars ) { + $chars = array_merge( $chars, range( 48, 57 ), range( 65, 90 ), range( 97, 122 ) ); + } + if ( $specialChars ) { + $chars = array_merge( $chars, range( 33, 47 ), range( 58, 64 ), range( 91, 96 ), range( 123, 126 ) ); + } + array_walk( $chars, function( &$val ) { + if ( !is_int( $val ) ) { + $val = ord( $val ); } + } + ); + if ( is_int( $len ) ) { + while ( $len ) { + $tmp = ord( openssl_random_pseudo_bytes( 1 ) ); + if ( in_array( $tmp, $chars ) ) { + if ( !$output || !in_array( $output, range( 1, 5 ) ) || $output == 3 || $output == 5 ) { + $out .= ( $output == 3 ) ? $tmp : chr( $tmp ); + } + else { + $based = base_convert( $tmp, 10, $outputMap[$output] ); + $out .= ( ( ( $output == 1 ) ? '00' : ( ( $output == 4 ) ? '0x' : '' ) ) . ( ( $output == 2 ) ? sprintf( '%03d', $based ) : $based ) ); + } + $len--; + } + } + } + return ( empty( $out ) ) ? false : $out; + } + } diff --git a/code/web/private_php/ams/plugins/API_key_management/templates/gen_key.tpl b/code/web/private_php/ams/plugins/API_key_management/templates/gen_key.tpl new file mode 100644 index 000000000..1ab283449 --- /dev/null +++ b/code/web/private_php/ams/plugins/API_key_management/templates/gen_key.tpl @@ -0,0 +1,46 @@ +
Please enter all the fields
Key added successfully
Key deleted successfully
All the keys you have generated will be shown and you can customize from here.
{$hook_info.Achievements.no_char}
{$ip_support}
+{$ip_success}
{$dp_error}
{$dp_success}
{$ac_success}
{$ac_error}
{$dc_success}
{$dc_error}
{$up_success}
{$up_install_success}
{$plugin_info}
{$up_info}