Code Search for Developers
 
 
  

featurecodes.class.php from freePBX at Krugle


Show featurecodes.class.php syntax highlighted

<?php
class featurecode
{
	var $_modulename;	// Module name
	var $_featurename;	// Feature name
	var $_description;	// Description (i.e. what the user will see)
	var $_defaultcode;	// Default code if user doesn't pick one
	var $_customcode;	// Custom code
	var $_enabled;		// Enabled/Disabled (0=disabled; 1=enabled; -1=unknown)
	var $_loaded;		// If this feature code was succesfully loaded from the DB

	// CONSTRUCTOR
	function featurecode($modulename, $featurename) {
		if ($modulename == '' || $featurename == '')
			die_freepbx('feature code class must be called with ModuleName and FeatureName');

		$this->_modulename = $modulename;
		$this->_featurename = $featurename;
		$this->_enabled = -1;  // -1 means not initialised
		$this->_loaded = false;
	}

	// HAS BEEN INIT'D ????
	function isReady() {
		return (!($this->_enabled == -1));
	}
	
	// INIT FUNCTION -- READS FROM DATABASE IF THERE BASICALLY
	// $opt = 0 -- called by user code (i.e. outside this class)
	// $opt = 1 -- called automatically by this class
	// $opt = 2 -- called by user code, run even if called once already
	function init($opt = 0) {
		if ($this->isReady()) {
			if ($opt < 2)
				die_freepbx('FeatureCode: init already called!');
		}
			
		$s = "SELECT description, defaultcode, customcode, enabled ";
		$s .= "FROM featurecodes ";
		$s .= "WHERE modulename = ".sql_formattext($this->_modulename)." AND featurename = ".sql_formattext($this->_featurename)." ";
		
		$res = sql($s, "getRow");
		if (is_array($res)) { // found something, read it
			$this->_description = $res[0];
			$this->_defaultcode = $res[1];
			$this->_customcode = $res[2];
			$this->_enabled = $res[3];
			
			$this->_loaded = true;

			return true;
		} else {
			
			return false;
		}
	}
	
	// UPDATE FUNCTION -- WRITES CURRENT STUFF BACK TO DATABASE
	function update() {
		global $amp_conf;
		if ($this->_enabled == -1) {
			// not explicitly set, old default was to enable by default, we will preserve that behaviour
			$this->_enabled = 1;
		}

		if (!$this->isReady())
			die_freepbx('FeatureCode: class function init never called...will not update');

		
		if ($this->_loaded) {
			$sql = 'UPDATE featurecodes SET '.
			       'description = '.sql_formattext($this->_description).', '.
			       'defaultcode = '.sql_formattext($this->_defaultcode).', '.
			       'customcode = '.sql_formattext($this->_customcode).', '.
			       'enabled = '.sql_formattext($this->_enabled).' '.
			       'WHERE modulename = '.sql_formattext($this->_modulename).
			       ' AND featurename = '.sql_formattext($this->_featurename);
		} else {
			$sql = 'INSERT INTO featurecodes (modulename, featurename, description, defaultcode, customcode, enabled) '.
			       '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).') ';
		}

		sql($sql, 'query');
		
		return true;
	}
	
	// SET DESCRIPTION
	function setDescription($description) {
		if (!$this->isReady())
			$this->init(1);

		if ($description == '') {
			unset($this->_description);
		} else {
			$this->_description = $description;
		}
	}
	
	// GET DESCRIPTION
	function getDescription() {
		if (!$this->isReady())
			$this->init(1);
		
		$desc = (isset($this->_description) ? $this->_description : '');
		
		return ($desc != '' ? $desc : $this->_featurename);
	}
	
	// SET DEFAULT CODE
	function setDefault($deafultcode, $defaultenabled = true) {
		if (!$this->isReady())
			$this->init(1);
			
		if ($deafultcode == '') {
			unset($this->_defaultcode);
		} else {
			$this->_defaultcode = $deafultcode;			
		}

		if ($this->_enabled == -1) {
			$this->_enabled = ($defaultenabled) ? 1 : 0;
		}


	}
	
	// GET DEFAULT CODE
	function getDefault() {
		if (!$this->isReady())
			$this->init(1);
		
		$def = (isset($this->_defaultcode) ? $this->_defaultcode : '');
		
		return $def;
	}
	
	// SET CUSTOM CODE
	function setCode($customcode) {
		if (!$this->isReady())
			$this->init(1);

		if ($customcode == '') {
			unset($this->_customcode);
		} else {
			$this->_customcode = $customcode;
		}
	}
	
	// GET FEATURE CODE -- DEFAULT OR CUSTOM IF SET
	//                     RETURN '' IF NOT AVAILABLE
	function getCode() {
		if (!$this->isReady())
			$this->init(1);

		$curcode = (isset($this->_customcode) ? $this->_customcode : '');
		$defcode = (isset($this->_defaultcode) ? $this->_defaultcode : '');
		
		return ($curcode == '' ? $defcode : $curcode);
	}
	
	// GET FEATURE CODE ONLY IF ENABLED
	function getCodeActive() {
		if ($this->isEnabled()) {
			return $this->getCode();
		} else {
			return '';
		}
	}
	
	// SET ENABLED
	function setEnabled($b = true) {
		if (!$this->isReady())
			$this->init(1);

		$this->_enabled = ($b ? 1 : 0);
	}
	
	// GET ENABLED
	function isEnabled() {
		if (!$this->isReady())
			$this->init(1);

		return ($this->_enabled == 1);
	}

	function delete() {
		$s = "DELETE ";
		$s .= "FROM featurecodes ";
		$s .= "WHERE modulename = ".sql_formattext($this->_modulename)." ";
		$s .= "AND featurename = ".sql_formattext($this->_featurename);
		sql($s, 'query');
		
		$this->_enabled = -1; // = not ready
		
		return true;
	}
}

// Helpers for eleswhere

// Return Array() of 'enabled' features for a specific module
function featurecodes_getModuleFeatures($modulename) {
	$s = "SELECT featurename, description ";
	$s .= "FROM featurecodes ";
	$s .= "WHERE modulename = ".sql_formattext($modulename)." AND enabled = 1 ";

	$results = sql($s, "getAll", DB_FETCHMODE_ASSOC);

	if (is_array($results)) {
		return $results;
	} else {
		return null;
		
	}
}

function featurecodes_getAllFeaturesDetailed() {
	$s = "SELECT featurecodes.modulename, featurecodes.featurename, featurecodes.description AS featuredescription, featurecodes.enabled AS featureenabled, featurecodes.defaultcode, featurecodes.customcode, ";
	$s .= "modules.enabled AS moduleenabled ";
	$s .= "FROM featurecodes ";
	$s .= "INNER JOIN modules ON modules.modulename = featurecodes.modulename ";
	$s .= "ORDER BY featurecodes.modulename, featurecodes.description ";
	
	$results = sql($s, "getAll", DB_FETCHMODE_ASSOC);
	if (is_array($results)) {
		$modules = module_getinfo(false, MODULE_STATUS_ENABLED);
		foreach ($results as $key => $item) {
			// get the module display name
			$results[$key]['moduledescription'] = (!empty($modules[ $item['modulename'] ]['name']) ? $modules[ $item['modulename'] ]['name'] : ucfirst($item['modulename']));
		}
		
		return $results;
	} else {
		return null;
	}
}

// removes all features for a specific module
function featurecodes_delModuleFeatures($modulename) {
       $s = "DELETE ";
       $s .= "FROM featurecodes ";
       $s .= "WHERE modulename = ".sql_formattext($modulename);

       sql($s, 'query');

       return true;
}

function featurecodes_getFeatureCode($modulename, $featurename) {
	$fc_code = '';
	
	$fcc = new featurecode($modulename, $featurename);
	$fc_code = $fcc->getCodeActive();
	unset($fcc);

	return $fc_code != '' ? $fc_code : _('** MISSING FEATURE CODE **');
}

function featurecodes_delFeatureCode($modulename, $featurename) {
       $s = "DELETE ";
       $s .= "FROM featurecodes ";
       $s .= "WHERE modulename = ".sql_formattext($modulename)." ";
       $s .= "AND featurename = ".sql_formattext($featurename);

       sql($s, 'query');

       return true;
}

?>




See more files for this project here

freePBX

FreePBX is the most powerful GUI (Web Based) configuration tool for Asterisk. It provides everything that a standard legacy phone system can, plus a huge amount of new features. All documentation and information is avalable from http://www.freepbx.org

Project homepage: http://sourceforge.net/projects/amportal
Programming language(s): PHP,Shell Script,SQL
License: other

  cdr/
    css/
      images/
        corner-bl.png
        corner-br.png
        corner-tl.png
        corner-tr.png
      content.css
      docbook.css
      layout.css
    images/
      asterisk.gif
      btn_top_12x12.gif
      button-search.gif
      call-compare.png
      call-logs.png
      excel.png
      fleche-d.gif
      fleche-g.gif
      header-download.png
      header-faq.png
      header-projects.png
      header-search.png
      icon_down_12x12.GIF
      icon_up_12x12.GIF
      jukebox_ti60.gif
      pdf.png
      print.css
      printable.png
      sidenav-selected.gif
      spacer.gif
      th_call-compare.png
      th_call-logs.png
    jpgraph_lib/
      imgdata_balls.inc
      imgdata_bevels.inc
      imgdata_diamonds.inc
      imgdata_pushpins.inc
      imgdata_squares.inc
      imgdata_stars.inc
      jpg-config.inc
      jpgraph.php
      jpgraph_antispam-digits.php
      jpgraph_antispam.php
      jpgraph_bar.php
      jpgraph_canvas.php
      jpgraph_canvtools.php
      jpgraph_error.php
      jpgraph_flags.php
      jpgraph_gantt.php
      jpgraph_gb2312.php
      jpgraph_gradient.php
      jpgraph_iconplot.php
      jpgraph_imgtrans.php
      jpgraph_line.php
      jpgraph_log.php
      jpgraph_pie.php
      jpgraph_pie3d.php
      jpgraph_plotband.php
      jpgraph_plotmark.inc
      jpgraph_polar.php
      jpgraph_radar.php
      jpgraph_regstat.php
      jpgraph_scatter.php
      jpgraph_stock.php
    lib/
      DB-modules/
      font/
      Class.Table.php
      defines.php
      fpdf.php
      iam_csvdump.php
    CHANGELOG.txt
    about.php
    call-comp.php
    call-daily-load.php
    call-last-month.php
    call-log.php
    cdr.php
    counter.txt
    encrypt.js
    export_csv.php
    export_pdf.php
    graph_hourdetail.php
    graph_pie.php
    graph_stat.php
    graph_statbar.php
    info.txt
  common/
    db_connect.php
    ie.css
    interface.dim.js
    jquery-1.1.3.1.js
    jquery.dimensions.js
    jquery.tabs-2.7.4.js
    json.inc.php
    libfreepbx.javascripts.js
    mainstyle-alternative.css
    mainstyle.css
    php-asmanager.php
    script.js.php
    script.legacy.js
    tabber-minimized.js
  i18n/
    de_DE/
    es_ES/
    fr_FR/
    he_IL/
    it_IT/
    pt_PT/
    ru_RU/
    readme.txt
  images/
    accept.png
    amp.png
    arrow_rotate_clockwise.png
    blank.gif
    cancel.png
    category1.png
    database_gear.png
    delete.gif
    freepbx.png
    freepbx_large.png
    freepbx_small.png
    header-back.png
    loading.gif
    logo.png
    modules-current1.png
    modules-hover1.png
    modules1.png
    scrolldown.gif
    scrollup.gif
    shadow-corner.png
    shadow-side-background.png
    shadow-side.png
    shadow-top.png
    tab-first-current.png
    tab-first.png
    tab-hover.png
    tab-select.png
    tab.png
    trash.png
    watermark.png
  modules/
    _cache/
    .htaccess
    import.sh
    modlist.sh
    remove.sh
    status.sh
    update.sh
  views/
    freepbx.php
    freepbx_admin.php
    freepbx_reload.php
    freepbx_reloadbar.php
    loggedout.php
    menuitem_disabled.php
    noaccess.php
    panel.php
    reports.php
    unauthorized.php
    welcome.php
    welcome_nomanager.php
  components.class.php
  config.php
  extensions.class.php
  favicon.ico
  featurecodes.class.php
  functions.inc.php
  header.php
  header_auth.php
  index.php
  page.modules.php
  panel.php
  reports.php