prepare("SELECT * FROM ivr_menus ORDER BY $sort_field $sort_order LIMIT :limit OFFSET :offset"); $query->bindParam(':limit' , $limit , PDO::PARAM_INT); $query->bindParam(':offset' , $offset , PDO::PARAM_INT); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } $ret = $query->fetchAll(PDO::FETCH_ASSOC); return $ret; } static function retrive($pk_menu) { $pdo = database::pdo(); /* Get general information about this ivr menu */ $query = $pdo->prepare("SELECT * FROM ivr_menus WHERE pk_menu=:pk_menu LIMIT 1"); $query->bindParam(':pk_menu', $pk_menu, PDO::PARAM_INT); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } $ret = $query->fetch(PDO::FETCH_ASSOC); /* If we have no results at the last query, return a null array */ if (empty($ret)) { return null; } return $ret; } static function save($data) { $pdo = database::pdo(); /* create a record in the ivr_menus table if this is a newly created ivr */ if ($data['pk_menu'] == "") { $query = $pdo->prepare("INSERT INTO ivr_menus(name) VALUES('')"); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } /* set the pk_menu to the autogenerated id */ $data['pk_menu'] = $pdo->lastInsertId('ivr_menus_pk_menu_seq'); } /* update the main ivr_menus table information */ $query = $pdo->prepare(" UPDATE ivr_menus SET name = :name, description = :description WHERE pk_menu = :pk_menu "); $query->bindValue(':name' , $data['name'] , PDO::PARAM_STR); $query->bindValue(':description', $data['description'], PDO::PARAM_STR); $query->bindValue(':pk_menu' , $data['pk_menu'] , PDO::PARAM_INT); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } /* update ivr aditional settings */ if (isset($data['fk_menu_invalid'])) { $query = $pdo->prepare(" UPDATE ivr_menus SET fk_menu_invalid = :fk_menu_invalid, fk_menu_timeout = :fk_menu_timeout, fk_menu_retry = :fk_menu_retry, fk_action_invalid = :fk_action_invalid, fk_action_timeout = :fk_action_timeout, fk_action_retry = :fk_action_retry, snd_language_invalid = :snd_language_invalid, snd_language_timeout = :snd_language_timeout, snd_language_retry = :snd_language_retry, snd_filename_timeout = :snd_filename_timeout, snd_filename_invalid = :snd_filename_invalid, snd_filename_retry = :snd_filename_retry, timeout = :timeout, retry = :retry, dialing = :dialing WHERE pk_menu = :pk_menu "); $query->bindValue(':fk_menu_invalid' , $data['fk_menu_invalid'] , PDO::PARAM_INT); $query->bindValue(':fk_action_invalid' , $data['fk_action_invalid'] , PDO::PARAM_INT); $query->bindValue(':snd_language_invalid', $data['snd_language_invalid'], PDO::PARAM_STR); $query->bindValue(':snd_filename_invalid', $data['snd_filename_invalid'], PDO::PARAM_STR); $query->bindValue(':fk_menu_timeout' , $data['fk_menu_timeout'] , PDO::PARAM_INT); $query->bindValue(':fk_action_timeout' , $data['fk_action_timeout'] , PDO::PARAM_INT); $query->bindValue(':snd_language_timeout', $data['snd_language_timeout'], PDO::PARAM_STR); $query->bindValue(':snd_filename_timeout', $data['snd_filename_timeout'], PDO::PARAM_STR); $query->bindValue(':fk_menu_retry' , $data['fk_menu_retry'] , PDO::PARAM_INT); $query->bindValue(':fk_action_retry' , $data['fk_action_retry'] , PDO::PARAM_INT); $query->bindValue(':snd_language_retry' , $data['snd_language_retry'] , PDO::PARAM_STR); $query->bindValue(':snd_filename_retry' , $data['snd_filename_retry'] , PDO::PARAM_STR); $query->bindValue(':retry' , $data['retry'] , PDO::PARAM_INT); $query->bindValue(':timeout' , $data['timeout'] , PDO::PARAM_INT); $query->bindValue(':dialing' , $data['dialing']?1:0 , PDO::PARAM_INT); $query->bindValue(':pk_menu' , $data['pk_menu'] , PDO::PARAM_INT); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } } return $data['pk_menu']; } static function validate($data) { $errors = array(); if(! preg_match('/^[a-zA-Z0-9 -+]{1,30}$/', $data['name'])) { $errors['name']['invalid'] = true; } return $errors; } static function generate() { $ret = array(); return $ret; } static function count() { $pdo = database::pdo(); $query = $pdo->prepare("SELECT COUNT(*) AS count FROM ivr_menus"); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } $ret = $query->fetch(PDO::FETCH_ASSOC); return $ret['count']; } static function delete($pk_menu) { $pdo = database::pdo(); /* Delete entry from the ivr_menus table */ $query = $pdo->prepare("DELETE FROM ivr_menus WHERE pk_menu = :pk_menu"); $query->bindParam(':pk_menu', $pk_menu, PDO::PARAM_INT); $query->execute(); if ($query->errorCode() != '00000') { $error = $query->errorInfo(); throw new Exception($error[2]); } /* Delete all actions associated with this ivr menu */ $ivr_actions = ivr_actions::records('pk_action', 'asc', 0, -1, $pk_menu); foreach ($ivr_actions as $ivr_action) { ivr_actions::delete($ivr_action['pk_action']); } /* Delete all options associated with this ivr menu */ $ivr_options = ivr_options::records('pk_option', 'asc', 0, -1, $pk_menu); foreach ($ivr_options as $ivr_option) { ivr_options::delete($ivr_option['pk_option']); } } }