Changeset 1386

Show
Ignore:
Timestamp:
04/07/06 08:09:08 (7 years ago)
Author:
mheydon1973
Message:

Some featurecode cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/featurecodes.class.php

    r1376 r1386  
    2525   
    2626  // INIT FUNCTION -- READS FROM DATABASE IF THERE BASICALLY 
    27   function init() { 
    28     if ($this->isReady()) 
    29       die('FeatureCode: init already called!'); 
     27  // $opt = 0 -- called by user code (i.e. outside this class) 
     28  // $opt = 1 -- called automatically by this class 
     29  // $opt = 2 -- called by user code, run even if called once already 
     30  function init($opt = 0) { 
     31    if ($this->isReady()) { 
     32      if ($opt < 2) 
     33        die('FeatureCode: init already called!'); 
     34    } 
    3035       
    3136    $s = "SELECT description, defaultcode, customcode, enabled "; 
    3237    $s .= "FROM featurecodes "; 
    33     $s .= "WHERE modulename = '$this->_modulename' AND featurename = '$this->_featurename'"; 
     38    $s .= "WHERE modulename = ".sql_formattext($this->_modulename)." AND featurename = ".sql_formattext($this->_featurename)." "; 
    3439     
    3540    $res = sql($s, "getRow"); 
     
    5257  function update() { 
    5358    if (!$this->isReady()) 
    54       die('FeatureCode: you must call init function before using'); 
     59      die('FeatureCode: class function init never called...will not update'); 
    5560 
    5661    $s = "REPLACE INTO featurecodes (modulename, featurename, description, defaultcode, customcode, enabled) "; 
    57     $s .= "VALUES ('$this->_modulename', '$this->_featurename', '$this->_description', '$this->_defaultcode', '$this->_customcode', $this->_enabled) "; 
     62    $s .= "VALUES (".sql_formattext($this->_modulename).", ".sql_formattext($this->_featurename).", ".sql_formattext($this->_description).", ".sql_formattext($this->_defaultcode).", ".sql_formattext($this->_customcode).", ".sql_formattext($this->_enabled).") "; 
    5863    sql($s, "query"); 
    5964     
     
    6469  function setDescription($description) { 
    6570    if (!$this->isReady()) 
    66       die('FeatureCode: you must call init function before using'); 
     71      $this->init(1); 
    6772 
    6873    if ($description == '') { 
     
    7681  function getDescription() { 
    7782    if (!$this->isReady()) 
    78       die('FeatureCode: you must call init function before using'); 
     83      $this->init(1); 
    7984     
    8085    $desc = (isset($this->_description) ? $this->_description : ''); 
     
    8691  function setDefault($deafultcode) { 
    8792    if (!$this->isReady()) 
    88       die('FeatureCode: you must call init function before using'); 
     93      $this->init(1); 
    8994       
    9095    if ($deafultcode == '') { 
     
    98103  function setCode($customcode) { 
    99104    if (!$this->isReady()) 
    100       die('FeatureCode: you must call init function before using'); 
     105      $this->init(1); 
    101106 
    102107    if ($customcode == '') { 
     
    111116  function getCode() { 
    112117    if (!$this->isReady()) 
    113       die('FeatureCode: you must call init function before using'); 
     118      $this->init(1); 
    114119 
    115120    $curcode = (isset($this->_customcode) ? $this->_customcode : ''); 
     
    130135  // SET ENABLED 
    131136  function setEnabled($b = true) { 
     137    if (!$this->isReady()) 
     138      $this->init(1); 
     139 
    132140    $this->_enabled = ($b ? 1 : 0); 
    133141  } 
     
    135143  // GET ENABLED 
    136144  function isEnabled() { 
     145    if (!$this->isReady()) 
     146      $this->init(1); 
     147 
    137148    return ($this->_enabled == 1); 
    138149  } 
     
    145156  $s = "SELECT featurename, description "; 
    146157  $s .= "FROM featurecodes "; 
    147   $s .= "WHERE modulename = '$modulename' AND enabled = 1 "; 
     158  $s .= "WHERE modulename = ".sql_formattext($modulename)." AND enabled = 1 "; 
    148159 
    149160  $results = sql($s,"getAll",DB_FETCHMODE_ASSOC); 
  • freepbx/trunk/amp_conf/htdocs/admin/functions.inc.php

    r1380 r1386  
    252252  } 
    253253  return $results; 
     254} 
     255 
     256// sql text formatting -- couldn't see that one was available already 
     257function sql_formattext($txt) { 
     258  if (isset($txt)) { 
     259    $fmt = str_replace("'", "''", $txt); 
     260    $fmt = "'" . $fmt . "'"; 
     261  } else { 
     262    $fmt = 'null'; 
     263  } 
     264 
     265  return $fmt; 
    254266} 
    255267 
  • freepbx/trunk/amp_conf/htdocs/admin/modules/callwaiting/functions.inc.php

    r1379 r1386  
    1212} 
    1313function callwaiting_install() { 
    14   // Register FeatureCodes 
    15   // Activate 
     14  // Register FeatureCode - Activate 
    1615  $fcc = new featurecode('callwaiting', 'cwon'); 
    17   $fcc->init(); 
    1816  $fcc->setDescription('Call Waiting - Activate'); 
    1917  $fcc->setDefault('*70'); 
    2018  $fcc->update(); 
    2119  unset($fcc); 
    22   // Deactivate 
     20 
     21  // Register FeatureCode - Deactivate 
    2322  $fcc = new featurecode('callwaiting', 'cwoff'); 
    24   $fcc->init(); 
    2523  $fcc->setDescription('Call Waiting - Deactivate'); 
    2624  $fcc->setDefault('*71'); 
     
    4240          if (function_exists($fname)) { 
    4341            $fcc = new featurecode($modulename, $featurename); 
    44             $fcc->init(); 
    4542            $fc = $fcc->getCodeActive(); 
    4643            unset($fcc);