diff --git a/gulliver/system/class.form.php b/gulliver/system/class.form.php index 8e90da87b..1c335d25c 100755 --- a/gulliver/system/class.form.php +++ b/gulliver/system/class.form.php @@ -1,6 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -25,585 +27,605 @@ */ /** * Class Form + * * @author David S. Callizaya S. * @package gulliver.system * @access public */ class Form extends XmlForm { - var $id=''; - var $width = 600; - var $title = ''; - var $fields = array(); - var $values = array(); - var $action = ''; - var $ajaxServer = ''; - var $enableTemplate = false; - var $ajaxSubmit = false; - var $callback='function(){}'; - var $in_progress='function(){}'; - var $template; - var $className="formDefault"; - var $objectRequiredFields = null; - var $nextstepsave = ''; - var $printdynaform = ''; - var $adjustgridswidth = '0'; + public $id = ''; + public $width = 600; + public $title = ''; + public $fields = array (); + public $values = array (); + public $action = ''; + public $ajaxServer = ''; + public $enableTemplate = false; + public $ajaxSubmit = false; + public $callback = 'function(){}'; + public $in_progress = 'function(){}'; + public $template; + public $className = "formDefault"; + public $objectRequiredFields = null; + public $nextstepsave = ''; + public $printdynaform = ''; + public $adjustgridswidth = '0'; - public $visual_frontend; + public $visual_frontend; - /** - * Function setDefaultValues - * @author David S. Callizaya S. - * @access public - * @return string - */ - function setDefaultValues( ) - { - foreach($this->fields as $name => $content) { - if (is_object($content) && get_class($content) != '__PHP_Incomplete_Class') { - if (isset($content->defaultValue)) - $this->values[$name] = $content->defaultValue; - else - $this->values[$name] = ''; - } - else { - $this->values[$name] = ''; - } - } - foreach($this->fields as $k => $v){ - if (is_object($v)) {//julichu - $this->fields[$k]->owner =& $this; - } - } - } - - /** - * Function Form - * @author David S. Callizaya S. - * @access public - * @param string filename - * @param string home - * @param string language - * @param string forceParse - * @param string $visual_frontend - * @return string - */ - function Form($filename, $home='', $language = '', $forceParse = false, $visual_frontend=null) - { - $this->visual_frontend = $visual_frontend; - if ($language=== '') - $language = defined('SYS_LANG')? SYS_LANG : 'en'; - if ($home=== '') - $home = defined('PATH_XMLFORM')? PATH_XMLFORM : - (defined('PATH_DYNAFORM')? PATH_DYNAFORM: ''); - //to do: obtain the error code in case the xml parsing has errors: DONE - //Load and parse the xml file - if ( substr($filename, -4) !== '.xml' ) - $filename = $filename . '.xml'; - $this->home=$home; - $res = parent::parseFile( $filename , $language, $forceParse ); - if ($res==1) - trigger_error('Faild to parse file ' . $filename . '.', E_USER_ERROR ); - if ($res==2) - trigger_error('Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR ); - $this->setDefaultValues(); - //to do: review if you can use the same form twice. in order to use once or not. - //DONE: Use require to be able to use the same xmlform more than once. - foreach($this->fields as $k => $v) { - //too memory? but it fails if it's loaded with baneco.xml with SYS_LANG='es' - //NOTE: This fails apparently when class of ($this->fields[$k]) is PHP_Incomplete_Class (because of cache) - if (is_object($v)) {//julichu - $this->fields[$k]->owner =& $this; - if ($this->fields[$k]->type==='grid') $this->fields[$k]->parseFile($home, $language); - } - } - $this->template = PATH_CORE . 'templates/'.$this->type.'.html'; - } - - /** - * Function printTemplate - * @author David S. Callizaya S. - * @access public - * @param string template - * @param string scriptContent - * @return string - */ - function printTemplate( $template, &$scriptContent ) - { - if (!file_exists($template)){ - throw(new Exception('Template "'.basename($template).'" doesn`t exist.')); - } - $o = new xmlformTemplate($this, $template); - if (is_array(reset($this->values))) - $this->rows=count(reset($this->values)); - if ($this->enableTemplate) { - $filename = substr($this->fileName , 0, -3) . - ( $this->type==='xmlform' ? '' : '.' . $this->type ) . 'html'; - if (!file_exists( $filename )) { - $o->template = $o->printTemplate( $this ); - $f=fopen($filename, 'w+'); - fwrite($f, $o->template); - fclose($f); - } - $o->template = implode( '', file( $filename ) ); - } else { - $o->template = $o->printTemplate( $this ); - } - return $o->template; - } - - /** - * Function render - * @author David S. Callizaya S. - * @access public - * @param string template - * @param string scriptContent - * @return string - */ - function render( $template, &$scriptContent ) - { - /*** - * This section was added for store the current used template. - */ - $tmp_var = explode('/', $template); - if( is_array($tmp_var) ){ - $tmp_var = $tmp_var[sizeof($tmp_var)-1]; - $this->using_template = $tmp_var; - } - /***/ - $this->template = $template; - $o = new xmlformTemplate($this, $template); - $values = $this->values; - $aValuekeys=array_keys($values); - if (isset($aValuekeys[0]) && ((int)$aValuekeys[0]==1)) - $values=XmlForm_Field_Grid::flipValues($values); - //TODO: Review when $values of a grid has only one row it is converted as a $values for a list (when template="grid" at addContent()) - if (is_array(reset($values))) { - $this->rows=count(reset($values)); - } - if ($this->enableTemplate) { - $filename = substr($this->fileName, 0, -3) . 'html'; - if (!file_exists( $filename )) { - $o->template = $o->printTemplate( $this ); - $f=fopen($filename, 'w+'); - fwrite($f, $o->template); - fclose($f); - } - $o->template = implode( '', file( $filename ) ); - } else { - $o->template = $o->printTemplate( $this ); - } - $scriptContent = $o->printJavaScript( $this ); - $content = $o->printObject($this); - return $content; - } - - /** - * Function setValues - * @author David S. Callizaya S. - * @access public - * @param array $newValues - * @return string - */ - function setValues($newValues=array()) - { - if ( !is_array ( $newValues) ){ - return; - } - foreach($this->fields as $k => $v){ - if ( array_key_exists($k,$newValues) ) { - if ( is_array($newValues[$k]) ) { - $this->values[$k] = array(); - foreach( $newValues[$k] as $j => $item ) { - if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )) - $this->values[$k][$j] = $newValues[$k][$j]; - } - if ((sizeof($this->values[$k])===1) && ($v->type!=='grid') && isset($this->values[$k][0]) ) - $this->values[$k] = $this->values[$k][0]; - if (sizeof($this->values[$k])===0) - $this->values[$k] = ''; - } else { - if ($this->fields[$k]->validateValue($newValues[$k], $this )) - $this->values[$k] = $newValues[$k]; - } - } - } - foreach ($newValues as $k => $v) { - if (strpos($k,'SYS_GRID_AGGREGATE_') !== false) { - $this->values[$k] = $newValues[$k]; - } - } - foreach($this->fields as $k => $v){ - if(is_object($this->fields[$k]) && get_class($this->fields[$k])!='__PHP_Incomplete_Class'){ - $this->fields[$k]->owner =& $this; - } - } - if(isset($this->labelWidth)){ - $nMaxPorcent = 1024; - $nWidth = stripos($this->width, '%'); - if($nWidth > 0) { - $sStrFind = $this->width; - $result = substr($sStrFind, 0, strpos($sStrFind, '%')); - $nWidth = (int)(($nMaxPorcent/100)*$result); - } else { - $nWidth = (int)$this->width; - $nMaxPorcent = $nWidth; - } - $nLabelWidth = stripos($this->labelWidth, '%'); - if($nLabelWidth > 0) { - $sStrFind = $this->labelWidth; - $result = substr($sStrFind, 0, strpos($sStrFind, '%')); - $nLabelWidth = (int)(($nWidth/100)*$result); - } else { - $nLabelWidth = (int)$this->labelWidth; - } - // krumo($nWidth,$nLabelWidth); - if(($nWidth - $nLabelWidth) > 0) - $this->fieldContentWidth = (int)($nWidth - $nLabelWidth); - } - } - - /** - * Function getFields - * @author David S. Callizaya S. - * @access public - * @param string template - * @param int $therow - * @return string - */ - function getFields($template, $therow = -1) - { - $o = new xmlformTemplate($this, $template); - return $o->getFields( $this, $therow ); - } - - /** - * Function that validates the values retrieved in $_POST - * @author David S. Callizaya S. - * @access public - * @return array $_POST['form'] - */ - function validatePost() - { - $_POST['form']=$this->validateFields($_POST['form']); - return $_POST['form']=$this->validateArray($_POST['form']); - } - - /** - * Function that validates the values retrieved in an Array: - * ex $_POST['form'] - * @author David S. Callizaya S. - * @access public - * @param array $newValues - * @return array - */ - function validateArray($newValues) - { - $values = array(); - foreach($this->fields as $k => $v) { - if (($v->type != 'submit')) { - if ($v->type != 'file') { - if ( array_key_exists($k,$newValues) ) { - - switch($v->type){ - case 'radiogroup': - $values[$k] = $newValues[$k]; - $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; - break; - - case 'suggest': - $values[$k] = $newValues[$k]; - $values[$k . "_label"] = $newValues[$k . "_label"]; - break; - - case 'checkgroup': - - case 'listbox': - if ( is_array($newValues[$k]) ) { - $values[$k] = $values[$k . "_label"] = null; - foreach ($newValues[$k] as $i => $value) { - //if $value is empty continue with the next loop, because this is a not selected/checked item - if (trim($value) == '') { - continue; - } - - $values[$k] .= (($i != 0)? "|" : null) . $value; - - if (isset($v->options[$value])){ - $values[$k . "_label"] .= (($i != 0)? "|" : null) . $v->options[$value]; - } - else { // if hasn't options try execute a sql sentence - $query = G::replaceDataField($this->fields[$k]->sql,$newValues); - - if ($query != '') { // execute just if a query was set, it should be not empty - //we do the query to the external connection and we've got the label - $con = Propel::getConnection($this->fields[$k]->sqlConnection!=""?$this->fields[$k]->sqlConnection:"workflow");//use default connection workflow if connection is not defined. Same as Dynaforms - - $stmt = $con->prepareStatement($query); - $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); - - while ($rs->next()) { - list($rowId, $rowContent) = array_values($rs->getRow());//This to be sure that the array is numeric. Some cases when is DBArray result it returns an associative. By JHL - - if ($value == $rowId){ - $values[$k . "_label"] .= (($i != 0)? "|" : null) . $rowContent; - break; - } - } - } - - } - } - - $newValues[$k . "_label"] = (isset($values[$k . "_label"]))? $values[$k . "_label"] : null; + /** + * Function setDefaultValues + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + public function setDefaultValues () + { + foreach ($this->fields as $name => $content) { + if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') { + if (isset( $content->defaultValue )) { + $this->values[$name] = $content->defaultValue; } else { - $values[$k] = $newValues[$k]; - $values[$k . "_label"] = (isset($newValues[$k . "_label"]))? $newValues[$k . "_label"] : null; + $this->values[$name] = ''; } - break; + } else { + $this->values[$name] = ''; + } + } + foreach ($this->fields as $k => $v) { + if (is_object( $v )) { + //julichu + $this->fields[$k]->owner = & $this; + } + } + } - case 'dropdown': - $values[$k] = $newValues[$k]; - - if (isset($v->options[$newValues[$k]])){ - $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; + /** + * Function Form + * + * @author David S. Callizaya S. + * @access public + * @param string filename + * @param string home + * @param string language + * @param string forceParse + * @param string $visual_frontend + * @return string + */ + public function Form ($filename, $home = '', $language = '', $forceParse = false, $visual_frontend = null) + { + $this->visual_frontend = $visual_frontend; + if ($language === '') { + $language = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + } + if ($home === '') { + $home = defined( 'PATH_XMLFORM' ) ? PATH_XMLFORM : (defined( 'PATH_DYNAFORM' ) ? PATH_DYNAFORM : ''); + } + //to do: obtain the error code in case the xml parsing has errors: DONE + //Load and parse the xml file + if (substr( $filename, - 4 ) !== '.xml') { + $filename = $filename . '.xml'; + } + $this->home = $home; + $res = parent::parseFile( $filename, $language, $forceParse ); + if ($res == 1) { + trigger_error( 'Faild to parse file ' . $filename . '.', E_USER_ERROR ); + } + if ($res == 2) { + trigger_error( 'Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR ); + } + $this->setDefaultValues(); + //to do: review if you can use the same form twice. in order to use once or not. + //DONE: Use require to be able to use the same xmlform more than once. + foreach ($this->fields as $k => $v) { + //too memory? but it fails if it's loaded with baneco.xml with SYS_LANG='es' + //NOTE: This fails apparently when class of ($this->fields[$k]) is PHP_Incomplete_Class (because of cache) + if (is_object( $v )) { + //julichu + $this->fields[$k]->owner = & $this; + if ($this->fields[$k]->type === 'grid') { + $this->fields[$k]->parseFile( $home, $language ); } - else { - $query = G::replaceDataField($this->fields[$k]->sql,$newValues); + } + } + $this->template = PATH_CORE . 'templates/' . $this->type . '.html'; + } - // execute just if a query was set, it should be not empty - if(trim($query) == '') { - continue; //if it is empty string skip it - } + /** + * Function printTemplate + * + * @author David S. Callizaya S. + * @access public + * @param string template + * @param string scriptContent + * @return string + */ + public function printTemplate ($template, &$scriptContent) + { + if (! file_exists( $template )) { + throw (new Exception( 'Template "' . basename( $template ) . '" doesn`t exist.' )); + } + $o = new xmlformTemplate( $this, $template ); + if (is_array( reset( $this->values ) )) { + $this->rows = count( reset( $this->values ) ); + } + if ($this->enableTemplate) { + $filename = substr( $this->fileName, 0, - 3 ) . ($this->type === 'xmlform' ? '' : '.' . $this->type) . 'html'; + if (! file_exists( $filename )) { + $o->template = $o->printTemplate( $this ); + $f = fopen( $filename, 'w+' ); + fwrite( $f, $o->template ); + fclose( $f ); + } + $o->template = implode( '', file( $filename ) ); + } else { + $o->template = $o->printTemplate( $this ); + } + return $o->template; + } - //we do the query to the external connection and we've got the label - $con = Propel::getConnection($this->fields[$k]->sqlConnection!=""?$this->fields[$k]->sqlConnection:"workflow"); - $stmt = $con->prepareStatement($query); - $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); - while ($rs->next()) { - list($rowId, $rowContent) = $rs->getRow(); - if ($newValues[$k]==$rowId){ - $values[$k . "_label"] = $rowContent; - break; + /** + * Function render + * + * @author David S. Callizaya S. + * @access public + * @param string template + * @param string scriptContent + * @return string + */ + public function render ($template, &$scriptContent) + { + /** + * * + * This section was added for store the current used template. + */ + $tmp_var = explode( '/', $template ); + if (is_array( $tmp_var )) { + $tmp_var = $tmp_var[sizeof( $tmp_var ) - 1]; + $this->using_template = $tmp_var; + } + /** + */ + $this->template = $template; + $o = new xmlformTemplate( $this, $template ); + $values = $this->values; + $aValuekeys = array_keys( $values ); + if (isset( $aValuekeys[0] ) && ((int) $aValuekeys[0] == 1)) { + $values = XmlForm_Field_Grid::flipValues( $values ); + } + //TODO: Review when $values of a grid has only one row it is converted as a $values for a list (when template="grid" at addContent()) + if (is_array( reset( $values ) )) { + $this->rows = count( reset( $values ) ); + } + if ($this->enableTemplate) { + $filename = substr( $this->fileName, 0, - 3 ) . 'html'; + if (! file_exists( $filename )) { + $o->template = $o->printTemplate( $this ); + $f = fopen( $filename, 'w+' ); + fwrite( $f, $o->template ); + fclose( $f ); + } + $o->template = implode( '', file( $filename ) ); + } else { + $o->template = $o->printTemplate( $this ); + } + $scriptContent = $o->printJavaScript( $this ); + $content = $o->printObject( $this ); + return $content; + } + + /** + * Function setValues + * + * @author David S. Callizaya S. + * @access public + * @param array $newValues + * @return string + */ + public function setValues ($newValues = array()) + { + if (! is_array( $newValues )) { + return; + } + foreach ($this->fields as $k => $v) { + if (array_key_exists( $k, $newValues )) { + if (is_array( $newValues[$k] )) { + $this->values[$k] = array (); + foreach ($newValues[$k] as $j => $item) { + if ($this->fields[$k]->validateValue( $newValues[$k][$j], $this )) { + $this->values[$k][$j] = $newValues[$k][$j]; + } + } + if ((sizeof( $this->values[$k] ) === 1) && ($v->type !== 'grid') && isset( $this->values[$k][0] )) { + $this->values[$k] = $this->values[$k][0]; + } + if (sizeof( $this->values[$k] ) === 0) { + $this->values[$k] = ''; + } + } else { + if ($this->fields[$k]->validateValue( $newValues[$k], $this )) { + $this->values[$k] = $newValues[$k]; } - } } - break; + } + } + foreach ($newValues as $k => $v) { + if (strpos( $k, 'SYS_GRID_AGGREGATE_' ) !== false) { + $this->values[$k] = $newValues[$k]; + } + } + foreach ($this->fields as $k => $v) { + if (is_object( $this->fields[$k] ) && get_class( $this->fields[$k] ) != '__PHP_Incomplete_Class') { + $this->fields[$k]->owner = & $this; + } + } + if (isset( $this->labelWidth )) { + $nMaxPorcent = 1024; + $nWidth = stripos( $this->width, '%' ); + if ($nWidth > 0) { + $sStrFind = $this->width; + $result = substr( $sStrFind, 0, strpos( $sStrFind, '%' ) ); + $nWidth = (int) (($nMaxPorcent / 100) * $result); + } else { + $nWidth = (int) $this->width; + $nMaxPorcent = $nWidth; + } + $nLabelWidth = stripos( $this->labelWidth, '%' ); + if ($nLabelWidth > 0) { + $sStrFind = $this->labelWidth; + $result = substr( $sStrFind, 0, strpos( $sStrFind, '%' ) ); + $nLabelWidth = (int) (($nWidth / 100) * $result); + } else { + $nLabelWidth = (int) $this->labelWidth; + } + // krumo($nWidth,$nLabelWidth); + if (($nWidth - $nLabelWidth) > 0) { + $this->fieldContentWidth = (int) ($nWidth - $nLabelWidth); + } + } + } - case 'grid': - foreach( $newValues[$k] as $j => $item ) { - if(is_array($item)){ - $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); - foreach ($item as $kk => $vv) { - if ($this->fields[$k]->fields[$kk]->type != "file") { - switch ($this->fields[$k]->fields[$kk]->type) { - case "dropdown": - //We need to know which fields are dropdowns - $values[$k][$j] = $newValues[$k][$j]; + /** + * Function getFields + * + * @author David S. Callizaya S. + * @access public + * @param string template + * @param int $therow + * @return string + */ + public function getFields ($template, $therow = -1) + { + $o = new xmlformTemplate( $this, $template ); + return $o->getFields( $this, $therow ); + } - if ($this->fields[$k]->validateValue($newValues[$k][$j], $this)) { - //If the dropdown has otions - if (isset($this->fields[$k]->fields[$kk]->options[$vv])) { - $values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"] = $this->fields[$k]->fields[$kk]->options[$vv]; + /** + * Function that validates the values retrieved in $_POST + * + * @author David S. Callizaya S. + * @access public + * @return array $_POST['form'] + */ + public function validatePost () + { + $_POST['form'] = $this->validateFields( $_POST['form'] ); + return $_POST['form'] = $this->validateArray( $_POST['form'] ); + } + + /** + * Function that validates the values retrieved in an Array: + * ex $_POST['form'] + * + * @author David S. Callizaya S. + * @access public + * @param array $newValues + * @return array + */ + public function validateArray ($newValues) + { + $values = array (); + foreach ($this->fields as $k => $v) { + if (($v->type != 'submit')) { + if ($v->type != 'file') { + if (array_key_exists( $k, $newValues )) { + + switch ($v->type) { + case 'radiogroup': + $values[$k] = $newValues[$k]; + $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; + break; + case 'suggest': + $values[$k] = $newValues[$k]; + $values[$k . "_label"] = $newValues[$k . "_label"]; + break; + case 'checkgroup': + case 'listbox': + if (is_array( $newValues[$k] )) { + $values[$k] = $values[$k . "_label"] = null; + foreach ($newValues[$k] as $i => $value) { + //if $value is empty continue with the next loop, because this is a not selected/checked item + if (trim( $value ) == '') { + continue; + } + + $values[$k] .= (($i != 0) ? "|" : null) . $value; + + if (isset( $v->options[$value] )) { + $values[$k . "_label"] .= (($i != 0) ? "|" : null) . $v->options[$value]; } else { - //If hasn't options try execute a sql sentence - $query = G::replaceDataField($this->fields[$k]->fields[$kk]->sql,$values[$k][$j]); - $con = Propel::getConnection((!empty($this->fields[$k]->fields[$kk]->sqlConnection))? $this->fields[$k]->fields[$kk]->sqlConnection : "workflow"); - $stmt = $con->prepareStatement($query); + // if hasn't options try execute a sql sentence + $query = G::replaceDataField( $this->fields[$k]->sql, $newValues ); - //Execute just if a query was set, it should be not empty - if (trim($query) == "") { - //if it is empty string skip it - continue; + if ($query != '') { + // execute just if a query was set, it should be not empty + //we do the query to the external connection and we've got the label + $con = Propel::getConnection( $this->fields[$k]->sqlConnection != "" ? $this->fields[$k]->sqlConnection : "workflow" ); //use default connection workflow if connection is not defined. Same as Dynaforms + + + $stmt = $con->prepareStatement( $query ); + $rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM ); + + while ($rs->next()) { + list ($rowId, $rowContent) = array_values( $rs->getRow() ); //This to be sure that the array is numeric. Some cases when is DBArray result it returns an associative. By JHL + + + if ($value == $rowId) { + $values[$k . "_label"] .= (($i != 0) ? "|" : null) . $rowContent; + break; + } + } } - $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); + } + } - while ($rs->next()) { - //From the query executed we only need certain elements - //note added by krlos pacha carlos[at]colosa[dot]com - //the following line has the correct values because the query return an associative array. Related 7945 bug - list($rowId, $rowContent) = explode(",", implode(",", $rs->getRow())); + $newValues[$k . "_label"] = (isset( $values[$k . "_label"] )) ? $values[$k . "_label"] : null; + } else { + $values[$k] = $newValues[$k]; + $values[$k . "_label"] = (isset( $newValues[$k . "_label"] )) ? $newValues[$k . "_label"] : null; + } + break; + case 'dropdown': + $values[$k] = $newValues[$k]; - if ($vv == $rowId) { - $values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk. "_label"] = $rowContent; - break; + if (isset( $v->options[$newValues[$k]] )) { + $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; + } else { + $query = G::replaceDataField( $this->fields[$k]->sql, $newValues ); + + // execute just if a query was set, it should be not empty + if (trim( $query ) == '') { + continue; //if it is empty string skip it + } + + //we do the query to the external connection and we've got the label + $con = Propel::getConnection( $this->fields[$k]->sqlConnection != "" ? $this->fields[$k]->sqlConnection : "workflow" ); + $stmt = $con->prepareStatement( $query ); + $rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM ); + while ($rs->next()) { + list ($rowId, $rowContent) = $rs->getRow(); + if ($newValues[$k] == $rowId) { + $values[$k . "_label"] = $rowContent; + break; + } + } + } + break; + case 'grid': + foreach ($newValues[$k] as $j => $item) { + if (is_array( $item )) { + $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); + foreach ($item as $kk => $vv) { + if ($this->fields[$k]->fields[$kk]->type != "file") { + switch ($this->fields[$k]->fields[$kk]->type) { + case "dropdown": + //We need to know which fields are dropdowns + $values[$k][$j] = $newValues[$k][$j]; + + if ($this->fields[$k]->validateValue( $newValues[$k][$j], $this )) { + //If the dropdown has otions + if (isset( $this->fields[$k]->fields[$kk]->options[$vv] )) { + $values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"] = $this->fields[$k]->fields[$kk]->options[$vv]; + } else { + //If hasn't options try execute a sql sentence + $query = G::replaceDataField( $this->fields[$k]->fields[$kk]->sql, $values[$k][$j] ); + $con = Propel::getConnection( (! empty( $this->fields[$k]->fields[$kk]->sqlConnection )) ? $this->fields[$k]->fields[$kk]->sqlConnection : "workflow" ); + $stmt = $con->prepareStatement( $query ); + + //Execute just if a query was set, it should be not empty + if (trim( $query ) == "") { + //if it is empty string skip it + continue; + } + + $rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM ); + + while ($rs->next()) { + //From the query executed we only need certain elements + //note added by krlos pacha carlos[at]colosa[dot]com + //the following line has the correct values because the query return an associative array. Related 7945 bug + list ($rowId, $rowContent) = explode( ",", implode( ",", $rs->getRow() ) ); + + if ($vv == $rowId) { + $values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"] = $rowContent; + break; + } + } + } + } + break; + default: + //If there are no dropdowns previously setted and the evaluated field is not a dropdown + //only then rewritte the $values + $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); + break; + } + } else { + if (isset( $_FILES["form"]["name"][$k][$j][$kk] )) { + $values[$k][$j][$kk] = $_FILES["form"]["name"][$k][$j][$kk]; + } + + if (isset( $this->fields[$k]->fields[$kk]->input ) && ! empty( $this->fields[$k]->fields[$kk]->input )) { + //$_POST["INPUTS"][$k][$j][$kk] = $this->fields[$k]->fields[$kk]->input; + $_POST["INPUTS"][$k][$kk] = $this->fields[$k]->fields[$kk]->input; } } } + } else { + $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); } - break; - default: - //If there are no dropdowns previously setted and the evaluated field is not a dropdown - //only then rewritte the $values - $values[$k][$j] = $this->fields[$k]->maskValue($newValues[$k][$j], $this); - break; - } - } else { - if (isset($_FILES["form"]["name"][$k][$j][$kk])) { - $values[$k][$j][$kk] = $_FILES["form"]["name"][$k][$j][$kk]; - } - - if (isset($this->fields[$k]->fields[$kk]->input) && !empty($this->fields[$k]->fields[$kk]->input)) { - //$_POST["INPUTS"][$k][$j][$kk] = $this->fields[$k]->fields[$kk]->input; - $_POST["INPUTS"][$k][$kk] = $this->fields[$k]->fields[$kk]->input; - } + } + break; + default: + if ($this->fields[$k]->validateValue( $newValues[$k], $this )) { + $values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this ); + } } } - } else { - $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); - } + } else { + if (isset( $_FILES["form"]["name"][$k] )) { + $values[$k] = $_FILES["form"]["name"][$k]; + } + + if (isset( $v->input ) && ! empty( $v->input )) { + $_POST["INPUTS"][$k] = $v->input; + } } - break; - - default: - if ($this->fields[$k]->validateValue($newValues[$k], $this )) - $values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this ); - - } - - } - } else { - if (isset($_FILES["form"]["name"][$k])) { - $values[$k] = $_FILES["form"]["name"][$k]; - } - - if (isset($v->input) && !empty($v->input)) { - $_POST["INPUTS"][$k] = $v->input; } } - } - } - foreach ($newValues as $k => $v) { - if (strpos($k, 'SYS_GRID_AGGREGATE_') !== false) { - $values[$k] = $v; - } - } - - return $values; - } - - /** - * Function that return the valid fields to replace - * @author Julio Cesar Laura Avendao?=o - * @access public - * @param boolean $bWhitSystemVars - * @return array - */ - function getVars($bWhitSystemVars = true) - { - $aFields = array(); - if ($bWhitSystemVars) { - $aAux = G::getSystemConstants(); - foreach ($aAux as $sName => $sValue) { - $aFields[] = array('sName' => $sName, 'sType' => 'system'); - } - } - foreach($this->fields as $k => $v) { - if (($v->type != 'title') && ($v->type != 'subtitle') && ($v->type != 'link') && - ($v->type != 'file') && ($v->type != 'button') && ($v->type != 'reset') && - ($v->type != 'submit') && ($v->type != 'listbox') && ($v->type != 'checkgroup') && - ($v->type != 'grid') && ($v->type != 'javascript')) { - $aFields[] = array('sName' => trim($k), 'sType' => trim($v->type)); - } - } - return $aFields; - } - - /** - * Function that verify the required fields without a correct value - * @author Erik Amaru Ortiz - * @access public - * @param array $dataFields - * @param array $noRequired - * @return array/false - */ - function validateRequiredFields($dataFields, $noRequired = array()) - { - if (!is_array($noRequired)) { - $noRequired = array(); - } - $requiredFields = array(); - $notPassedFields = array(); - $skippedFieldsTypes = array('javascript', 'checkbox', 'yesno', 'submit', 'button', 'title', 'subtitle', - 'button', 'submit', 'reset', 'hidden', 'link'); - $requiredFieldsGrids = array(); - $grids = array(); - - foreach ($this->fields as $field) { - // verify fields in grids - if($field->type == 'grid') { - array_push($grids, $field->name); - foreach ($field->fields as $fieldGrid) { - if (is_object($fieldGrid) && isset($fieldGrid->required) && $fieldGrid->required) { - if (!in_array($fieldGrid->type, $skippedFieldsTypes)) { - if ( !(is_array($requiredFieldsGrids[$field->name])) ) { - $requiredFieldsGrids[$field->name] = array(); - } - array_push($requiredFieldsGrids[$field->name], $fieldGrid->name); + foreach ($newValues as $k => $v) { + if (strpos( $k, 'SYS_GRID_AGGREGATE_' ) !== false) { + $values[$k] = $v; } - } } - } - // verify fields the form - if (is_object($field) && isset($field->required) && $field->required) { - if (!in_array($field->type, $skippedFieldsTypes)) { - array_push($requiredFields, $field->name); - } - } + return $values; } - foreach($dataFields as $dataFieldName => $dataField) { - if (in_array($dataFieldName, $grids)) { - foreach ($dataField as $indexGrid => $dataGrid) { - foreach ($dataGrid as $fieldGridName => $fieldGridValue) { - if (!is_array($requiredFieldsGrids[$dataFieldName])) { - $requiredFieldsGrids[$dataFieldName] = array(); - } - if (in_array($fieldGridName, $requiredFieldsGrids[$dataFieldName]) && !in_array($fieldGridName, $noRequired) && trim($fieldGridValue) == '') { - if ( !(is_array($notPassedFields[$dataFieldName])) ) { - $notPassedFields[$dataFieldName] = array(); - } - $notPassedFields[$dataFieldName][$indexGrid][] = $fieldGridName; - } - } - } - } - - //verify if the requiered field is in $requiredFields array - if (in_array($dataFieldName, $requiredFields) && !in_array($dataFieldName, $noRequired) && trim($dataField) == '') { - $notPassedFields[] = $dataFieldName; - } - } - - return count($notPassedFields) > 0 ? $notPassedFields : false; - } - - public function validateFields($data) + /** + * Function that return the valid fields to replace + * + * @author Julio Cesar Laura Avendao?=o + * @access public + * @param boolean $bWhitSystemVars + * @return array + */ + public function getVars ($bWhitSystemVars = true) { - $excludeTypes = array("submit", "file"); + $aFields = array (); + if ($bWhitSystemVars) { + $aAux = G::getSystemConstants(); + foreach ($aAux as $sName => $sValue) { + $aFields[] = array ('sName' => $sName,'sType' => 'system' + ); + } + } + foreach ($this->fields as $k => $v) { + if (($v->type != 'title') && ($v->type != 'subtitle') && ($v->type != 'link') && ($v->type != 'file') && ($v->type != 'button') && ($v->type != 'reset') && ($v->type != 'submit') && ($v->type != 'listbox') && ($v->type != 'checkgroup') && ($v->type != 'grid') && ($v->type != 'javascript')) { + $aFields[] = array ('sName' => trim( $k ),'sType' => trim( $v->type ) + ); + } + } + return $aFields; + } + + /** + * Function that verify the required fields without a correct value + * + * @author Erik Amaru Ortiz + * @access public + * @param array $dataFields + * @param array $noRequired + * @return array/false + */ + public function validateRequiredFields ($dataFields, $noRequired = array()) + { + if (! is_array( $noRequired )) { + $noRequired = array (); + } + $requiredFields = array (); + $notPassedFields = array (); + $skippedFieldsTypes = array ('javascript','checkbox','yesno','submit','button','title','subtitle','button','submit','reset','hidden','link' + ); + $requiredFieldsGrids = array (); + $grids = array (); + + foreach ($this->fields as $field) { + // verify fields in grids + if ($field->type == 'grid') { + array_push( $grids, $field->name ); + foreach ($field->fields as $fieldGrid) { + if (is_object( $fieldGrid ) && isset( $fieldGrid->required ) && $fieldGrid->required) { + if (! in_array( $fieldGrid->type, $skippedFieldsTypes )) { + if (! (is_array( $requiredFieldsGrids[$field->name] ))) { + $requiredFieldsGrids[$field->name] = array (); + } + array_push( $requiredFieldsGrids[$field->name], $fieldGrid->name ); + } + } + } + } + + // verify fields the form + if (is_object( $field ) && isset( $field->required ) && $field->required) { + if (! in_array( $field->type, $skippedFieldsTypes )) { + array_push( $requiredFields, $field->name ); + } + } + } + + foreach ($dataFields as $dataFieldName => $dataField) { + if (in_array( $dataFieldName, $grids )) { + foreach ($dataField as $indexGrid => $dataGrid) { + foreach ($dataGrid as $fieldGridName => $fieldGridValue) { + if (! is_array( $requiredFieldsGrids[$dataFieldName] )) { + $requiredFieldsGrids[$dataFieldName] = array (); + } + if (in_array( $fieldGridName, $requiredFieldsGrids[$dataFieldName] ) && ! in_array( $fieldGridName, $noRequired ) && trim( $fieldGridValue ) == '') { + if (! (is_array( $notPassedFields[$dataFieldName] ))) { + $notPassedFields[$dataFieldName] = array (); + } + $notPassedFields[$dataFieldName][$indexGrid][] = $fieldGridName; + } + } + } + } + + //verify if the requiered field is in $requiredFields array + if (in_array( $dataFieldName, $requiredFields ) && ! in_array( $dataFieldName, $noRequired ) && trim( $dataField ) == '') { + $notPassedFields[] = $dataFieldName; + } + } + + return count( $notPassedFields ) > 0 ? $notPassedFields : false; + } + + public function validateFields ($data) + { + $excludeTypes = array ("submit","file" ); foreach ($this->fields as $k => $v) { - if (!in_array($v->type, $excludeTypes)) { + if (! in_array( $v->type, $excludeTypes )) { switch ($v->type) { case "checkbox": - $data[$v->name] = (isset($data[$v->name]))? $data[$v->name] : ((isset($v->falseValue))? $v->falseValue : null); + $data[$v->name] = (isset( $data[$v->name] )) ? $data[$v->name] : ((isset( $v->falseValue )) ? $v->falseValue : null); break; case "grid": $i = 0; - foreach ($data[$v->name] as $dataGrid) { $i = $i + 1; foreach ($v->fields as $gridField) { switch ($gridField->type) { case "file": - $data[$v->name][$i][$gridField->name] = (isset($_FILES["form"]["name"][$v->name][$i][$gridField->name]))? $_FILES["form"]["name"][$v->name][$i][$gridField->name] : ((isset($gridField->falseValue))? $gridField->falseValue : null); + $data[$v->name][$i][$gridField->name] = (isset( $_FILES["form"]["name"][$v->name][$i][$gridField->name] )) ? $_FILES["form"]["name"][$v->name][$i][$gridField->name] : ((isset( $gridField->falseValue )) ? $gridField->falseValue : null); break; case "checkbox": - $data[$v->name][$i][$gridField->name] = (isset($data[$v->name][$i][$gridField->name]))? $data[$v->name][$i][$gridField->name] : ((isset($gridField->falseValue))? $gridField->falseValue : null); + $data[$v->name][$i][$gridField->name] = (isset( $data[$v->name][$i][$gridField->name] )) ? $data[$v->name][$i][$gridField->name] : ((isset( $gridField->falseValue )) ? $gridField->falseValue : null); break; } } @@ -614,7 +636,7 @@ class Form extends XmlForm } } } - return $data; } } + diff --git a/gulliver/system/class.functionTest.php b/gulliver/system/class.functionTest.php index a5d78d666..90a700039 100755 --- a/gulliver/system/class.functionTest.php +++ b/gulliver/system/class.functionTest.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** +/** + * * @package gulliver.system - **/ + * + */ class functionTest { - var $dbc; - var $times; - - /** - * Starts functionTest with a database connection - * - * @access public - * @param string $dbc - * @return void - * - */ - function functionTest( $dbc ) { - $this->dbc= $dbc; - } - - /** - * this function is a sample - * - * @access public - * @param string $testCase - * @param string $testDomain - * @param string $limeTestObject - * @return ok - * - */ - function sample( $testCase , &$testDomain , &$limeTestObject ) { - return "OK"; - } + public $dbc; + public $times; + + /** + * Starts functionTest with a database connection + * + * @access public + * @param string $dbc + * @return void + * + */ + public function functionTest ($dbc) + { + $this->dbc = $dbc; + } + + /** + * this function is a sample + * + * @access public + * @param string $testCase + * @param string $testDomain + * @param string $limeTestObject + * @return ok + * + */ + public function sample ($testCase, &$testDomain, &$limeTestObject) + { + return "OK"; + } } + diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index d28710b17..d8e080e83 100755 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -1,6 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -31,7 +33,7 @@ * @package gulliver.system * @copyright (C) 2002 by Colosa Development Team. * @link http://www.colosa.com - * @link http://manuals.colosa.com/gulliver/rbac.html + * @link http://manuals.colosa.com/gulliver/rbac.html * @author Fernando Ontiveros */ @@ -44,1072 +46,1131 @@ class RBAC { - /** - * - * @access private - * @var $userObj - */ - var $userObj; - var $usersPermissionsObj; - var $usersRolesObj; - var $systemObj; - var $rolesObj; - var $permissionsObj; - var $userloggedobj; - var $currentSystemobj; - var $rolesPermissionsObj; - var $authSourcesObj; + /** + * + * @access private + * @var $userObj + */ + public $userObj; + public $usersPermissionsObj; + public $usersRolesObj; + public $systemObj; + public $rolesObj; + public $permissionsObj; + public $userloggedobj; + public $currentSystemobj; + public $rolesPermissionsObj; + public $authSourcesObj; - var $aUserInfo = array(); - var $aRbacPlugins = array(); - var $sSystem = ''; + public $aUserInfo = array (); + public $aRbacPlugins = array (); + public $sSystem = ''; - var $singleSignOn = false; + public $singleSignOn = false; - static private $instance = NULL; + private static $instance = null; - public function __construct() { - } - - /** - * to get singleton instance - * - * @access public - * @return object - */ - function &getSingleton() { - if (self::$instance == NULL) { - self::$instance = new RBAC(); + public function __construct () + { } - return self::$instance; - } - - /** - * to get start with some classess - * - * @access public - * @return object - */ - function initRBAC () { - if ( is_null($this->userObj ) ) { - require_once ( "classes/model/RbacUsers.php" ); - $this->userObj = new RbacUsers(); - } - - if ( is_null($this->systemObj ) ) { - require_once ( "classes/model/Systems.php" ); - $this->systemObj = new Systems; - } - - if ( is_null($this->usersRolesObj ) ) { - require_once ( "classes/model/UsersRoles.php" ); - $this->usersRolesObj = new UsersRoles; - } - - if ( is_null($this->rolesObj ) ) { - require_once ( "classes/model/Roles.php" ); - $this->rolesObj = new Roles; - } - - if ( is_null($this->permissionsObj ) ) { - require_once ( "classes/model/Permissions.php" ); - $this->permissionsObj = new Permissions; - } - - if ( is_null($this->rolesPermissionsObj ) ) { - require_once ( "classes/model/RolesPermissions.php" ); - $this->rolesPermissionsObj = new RolesPermissions; - } - - if (is_null($this->authSourcesObj)) { - require_once 'classes/model/AuthenticationSource.php'; - $this->authSourcesObj = new AuthenticationSource(); - } - //hook for RBAC plugins - $pathPlugins = PATH_RBAC . 'plugins'; - if ( is_dir ( $pathPlugins ) ) { - if ($handle = opendir( $pathPlugins )) { - while ( false !== ($file = readdir($handle))) { - if ( strpos($file, '.php',1) && is_file( $pathPlugins . PATH_SEP . $file) && - substr($file,0,6) == 'class.' && substr($file,-4) == '.php' ) { - - $sClassName = substr($file,6, strlen($file) - 10); - require_once ($pathPlugins . PATH_SEP . $file); - $this->aRbacPlugins[] = $sClassName; - - } - } - } - } - } /** - * gets the Role and their permissions for Administrator Processmaker - * - * @access public - * @return $this->permissionsAdmin[ $permissionsAdmin ] - */ - function loadPermissionAdmin() { - $permissionsAdmin =array( - array("PER_UID"=>"00000000000000000000000000000001","PER_CODE"=>"PM_LOGIN"), - array("PER_UID"=>"00000000000000000000000000000002","PER_CODE"=>"PM_SETUP"), - array("PER_UID"=>"00000000000000000000000000000003","PER_CODE"=>"PM_USERS"), - array("PER_UID"=>"00000000000000000000000000000004","PER_CODE"=>"PM_FACTORY"), - array("PER_UID"=>"00000000000000000000000000000005","PER_CODE"=>"PM_CASES"), - array("PER_UID"=>"00000000000000000000000000000006","PER_CODE"=>"PM_ALLCASES"), - array("PER_UID"=>"00000000000000000000000000000007","PER_CODE"=>"PM_REASSIGNCASE"), - array("PER_UID"=>"00000000000000000000000000000008","PER_CODE"=>"PM_REPORTS"), - array("PER_UID"=>"00000000000000000000000000000009","PER_CODE"=>"PM_SUPERVISOR"), - array("PER_UID"=>"00000000000000000000000000000010","PER_CODE"=>"PM_SETUP_ADVANCE"), - array("PER_UID"=>"00000000000000000000000000000011","PER_CODE"=>"PM_DASHBOARD"), - array("PER_UID"=>"00000000000000000000000000000012","PER_CODE"=>"PM_WEBDAV"), - array("PER_UID"=>"00000000000000000000000000000013","PER_CODE"=>"PM_DELETECASE"), - array("PER_UID"=>"00000000000000000000000000000014","PER_CODE"=>"PM_EDITPERSONALINFO"), - array("PER_UID"=>"00000000000000000000000000000015","PER_CODE"=>"PM_FOLDERS_VIEW"), - array("PER_UID"=>"00000000000000000000000000000016","PER_CODE"=>"PM_FOLDERS_ADD_FOLDER"), - array("PER_UID"=>"00000000000000000000000000000017","PER_CODE"=>"PM_FOLDERS_ADD_FILE"), - array("PER_UID"=>"00000000000000000000000000000018","PER_CODE"=>"PM_CANCELCASE"), - array("PER_UID"=>"00000000000000000000000000000019","PER_CODE"=>"PM_FOLDER_DELETE") + * to get singleton instance + * + * @access public + * @return object + */ + public function &getSingleton () + { + if (self::$instance == null) { + self::$instance = new RBAC(); + } + return self::$instance; + } + + /** + * to get start with some classess + * + * @access public + * @return object + */ + public function initRBAC () + { + if (is_null( $this->userObj )) { + require_once ("classes/model/RbacUsers.php"); + $this->userObj = new RbacUsers(); + } + + if (is_null( $this->systemObj )) { + require_once ("classes/model/Systems.php"); + $this->systemObj = new Systems(); + } + + if (is_null( $this->usersRolesObj )) { + require_once ("classes/model/UsersRoles.php"); + $this->usersRolesObj = new UsersRoles(); + } + + if (is_null( $this->rolesObj )) { + require_once ("classes/model/Roles.php"); + $this->rolesObj = new Roles(); + } + + if (is_null( $this->permissionsObj )) { + require_once ("classes/model/Permissions.php"); + $this->permissionsObj = new Permissions(); + } + + if (is_null( $this->rolesPermissionsObj )) { + require_once ("classes/model/RolesPermissions.php"); + $this->rolesPermissionsObj = new RolesPermissions(); + } + + if (is_null( $this->authSourcesObj )) { + require_once 'classes/model/AuthenticationSource.php'; + $this->authSourcesObj = new AuthenticationSource(); + } + //hook for RBAC plugins + $pathPlugins = PATH_RBAC . 'plugins'; + if (is_dir( $pathPlugins )) { + if ($handle = opendir( $pathPlugins )) { + while (false !== ($file = readdir( $handle ))) { + if (strpos( $file, '.php', 1 ) && is_file( $pathPlugins . PATH_SEP . $file ) && substr( $file, 0, 6 ) == 'class.' && substr( $file, - 4 ) == '.php') { + + $sClassName = substr( $file, 6, strlen( $file ) - 10 ); + require_once ($pathPlugins . PATH_SEP . $file); + $this->aRbacPlugins[] = $sClassName; + + } + } + } + } + } + + /** + * gets the Role and their permissions for Administrator Processmaker + * + * @access public + * @return $this->permissionsAdmin[ $permissionsAdmin ] + */ + public function loadPermissionAdmin () + { + $permissionsAdmin = array (array ("PER_UID" => "00000000000000000000000000000001","PER_CODE" => "PM_LOGIN" + ),array ("PER_UID" => "00000000000000000000000000000002","PER_CODE" => "PM_SETUP" + ),array ("PER_UID" => "00000000000000000000000000000003","PER_CODE" => "PM_USERS" + ),array ("PER_UID" => "00000000000000000000000000000004","PER_CODE" => "PM_FACTORY" + ),array ("PER_UID" => "00000000000000000000000000000005","PER_CODE" => "PM_CASES" + ),array ("PER_UID" => "00000000000000000000000000000006","PER_CODE" => "PM_ALLCASES" + ),array ("PER_UID" => "00000000000000000000000000000007","PER_CODE" => "PM_REASSIGNCASE" + ),array ("PER_UID" => "00000000000000000000000000000008","PER_CODE" => "PM_REPORTS" + ),array ("PER_UID" => "00000000000000000000000000000009","PER_CODE" => "PM_SUPERVISOR" + ),array ("PER_UID" => "00000000000000000000000000000010","PER_CODE" => "PM_SETUP_ADVANCE" + ),array ("PER_UID" => "00000000000000000000000000000011","PER_CODE" => "PM_DASHBOARD" + ),array ("PER_UID" => "00000000000000000000000000000012","PER_CODE" => "PM_WEBDAV" + ),array ("PER_UID" => "00000000000000000000000000000013","PER_CODE" => "PM_DELETECASE" + ),array ("PER_UID" => "00000000000000000000000000000014","PER_CODE" => "PM_EDITPERSONALINFO" + ),array ("PER_UID" => "00000000000000000000000000000015","PER_CODE" => "PM_FOLDERS_VIEW" + ),array ("PER_UID" => "00000000000000000000000000000016","PER_CODE" => "PM_FOLDERS_ADD_FOLDER" + ),array ("PER_UID" => "00000000000000000000000000000017","PER_CODE" => "PM_FOLDERS_ADD_FILE" + ),array ("PER_UID" => "00000000000000000000000000000018","PER_CODE" => "PM_CANCELCASE" + ),array ("PER_UID" => "00000000000000000000000000000019","PER_CODE" => "PM_FOLDER_DELETE" + ) ); return $permissionsAdmin; } - /** - * Gets the roles and permission for one RBAC_user - * - * gets the Role and their permissions for one User - * - * @author Fernando Ontiveros Lira - * @access public - - * @param string $sSystem the system - * @param string $sUser the user - * @return $this->aUserInfo[ $sSystem ] - */ - function loadUserRolePermission( $sSystem, $sUser ) { - //in previous versions we provided a path data and session we will cache the session Info for this user - //now this is deprecated, and all the aUserInfo is in the memcache - - $this->sSystem = $sSystem; - $fieldsSystem = $this->systemObj->loadByCode($sSystem); - $fieldsRoles = $this->usersRolesObj->getRolesBySystem ($fieldsSystem['SYS_UID'], $sUser ); - $fieldsPermissions = $this->usersRolesObj->getAllPermissions ($fieldsRoles['ROL_UID'], $sUser ); - $this->aUserInfo['USER_INFO'] = $this->userObj->load( $sUser); - $this->aUserInfo[ $sSystem ]['SYS_UID'] = $fieldsSystem['SYS_UID']; - $this->aUserInfo[ $sSystem ]['ROLE'] = $fieldsRoles; - $this->aUserInfo[ $sSystem ]['PERMISSIONS'] = $fieldsPermissions; - } - - /** - * verification the register automatic - * - * - * @access public - * @param string $strUser the system - * @param string $strPass the password - * @return $res - */ - function checkAutomaticRegister( $strUser, $strPass) { - $result = -1; //default return value, - - foreach ( $this->aRbacPlugins as $sClassName) { - $plugin = new $sClassName(); - if ( method_exists($plugin, 'automaticRegister' ) ) { - $oCriteria = new Criteria('rbac'); - $oCriteria->add(AuthenticationSourcePeer::AUTH_SOURCE_PROVIDER, $sClassName ); - $oCriteria->addAscendingOrderByColumn(AuthenticationSourcePeer::AUTH_SOURCE_NAME ); - $oDataset = AuthenticationSourcePeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aRow = $oDataset->getRow(); - while ( is_array ( $aRow ) ) { - $aRow = array_merge ( $aRow, unserialize ( $aRow['AUTH_SOURCE_DATA'] ) ); - //Check if this authsource is enabled for AutoRegister, if not skip this - if ( $aRow['AUTH_SOURCE_AUTO_REGISTER'] == 1 ) { - $plugin->sAuthSource = $aRow['AUTH_SOURCE_UID']; - $plugin->sSystem = $this->sSystem; - //search the usersRolesObj - //create the users in ProcessMaker - $res = $plugin->automaticRegister($aRow, $strUser, $strPass); - if ( $res == 1 ) return $res; - } - $oDataset->next(); - $aRow = $oDataset->getRow(); - } - } - } - - } - - /** - * this function is checking the register automatic without authentication - * - * - * @access public - * @param string $sAuthType - * @param string $sAuthSource - * @param string $aUserFields - * @param string $sAuthUserDn - * @param string $strPass - * @return number - * -2: wrong password - * -3: inactive user - * -4: due date - * -5: invalid authentication source - */ - public function VerifyWithOtherAuthenticationSource($sAuthType, $aUserFields, $strPass) - { - //check if the user is active - if ( $aUserFields['USR_STATUS'] != 1 ) - return -3; //inactive user - - //check if the user's due date is valid - if ( $aUserFields['USR_DUE_DATE'] < date('Y-m-d') ) - return -4; //due date - - foreach ( $this->aRbacPlugins as $sClassName) { - if ( strtolower($sClassName) == strtolower($sAuthType) ) { - $plugin = new $sClassName(); - $plugin->sAuthSource = $aUserFields["UID_AUTH_SOURCE"]; - $plugin->sSystem = $this->sSystem; - $bValidUser = $plugin->VerifyLogin($aUserFields["USR_AUTH_USER_DN"], $strPass); - - if ( $bValidUser === TRUE) - return ( $aUserFields['USR_UID'] ); - else - return -2; //wrong password - - } - } - return -5; //invalid authentication source - } - - /** - * authentication of an user through of class RBAC_user - * - * checking that an user has right to start an applicaton - * - * @author Fernando Ontiveros Lira - * @access public - - * @param string $strUser UserId (login) an user - * @param string $strPass Password - * @return - * -1: no user - * -2: wrong password - * -3: inactive usuario - * -4: due date - * -5: invalid authentication source ( **new ) - * n : uid of user - */ - function VerifyLogin( $strUser, $strPass) - { - if ( strlen($strPass) == 0) return -2; - //check if the user exists in the table RB_WORKFLOW.USERS - $this->initRBAC(); - //if the user exists, the VerifyUser function will return the user properties - if ( $this->userObj->verifyUser($strUser) == 0 ) { - //here we are checking if the automatic user Register is enabled, ioc return -1 - $res = $this->checkAutomaticRegister( $strUser, $strPass); - if ( $res == 1 ) - $this->userObj->verifyUser($strUser); - else - return $res; - } - - //default values - $sAuthType = 'mysql'; - if ( isset($this->userObj->fields['USR_AUTH_TYPE']) ) $sAuthType = strtolower ( $this->userObj->fields['USR_AUTH_TYPE'] ); - - //Hook for RBAC plugins - if ($sAuthType != "mysql" && $sAuthType != "") { - $res = $this->VerifyWithOtherAuthenticationSource($sAuthType, $this->userObj->fields, $strPass); - - return $res; - } else { - $this->userObj->reuseUserFields = true; - $res = $this->userObj->VerifyLogin($strUser, $strPass); - - return $res; - } - } - - /** - * Verify if the user exist or not exists, the argument is the UserName - * - * @author Everth S. Berrios - * @access public - * @param string $strUser - * @return $res - */ - function verifyUser($strUser) { - $res = $this->userObj->verifyUser($strUser); - return $res; - } - - /** - * Verify if the user exist or not exists, the argument is the UserUID - * - * @author Everth S. Berrios - * @access public - * @param string $strUserId - * @return $res - */ - function verifyUserId($strUserId) { - $res = $this->userObj->verifyUserId($strUserId); - return $res; - } - - /** - * Verify if the user has a right over the permission - * - * @author Fernando Ontiveros - * @access public - - * @param string $uid id of user - * @param string $system Code of System - * @param string $perm id of Permissions - * @return - * 1: If it is ok - * -1: System doesn't exists - * -2: The User has not a Role - * -3: The User has not this Permission. - */ - function userCanAccess ($perm) - { - if ( isset ( $this->aUserInfo[ $this->sSystem ]['PERMISSIONS'] ) ) { - $res = -3; - //if ( !isset ( $this->aUserInfo[ $this->sSystem ]['ROLE'. 'x'] ) ) $res = -2; - foreach ( $this->aUserInfo[ $this->sSystem ]['PERMISSIONS'] as $key=>$val ) - if ( $perm == $val['PER_CODE'] ) $res = 1; - } - else - $res = -1; - - return $res; - } - - /** - * to create an user - * - * @access public - * @param array $aData - * @param string $sRolCode - * @return $sUserUID - */ - function createUser($aData = array(), $sRolCode = '') { - if ($aData['USR_STATUS'] == 'ACTIVE') { - $aData['USR_STATUS'] = 1; - } - if ($aData['USR_STATUS'] == 'INACTIVE') { - $aData['USR_STATUS'] = 0; - } - $sUserUID = $this->userObj->create($aData); - if ($sRolCode != '') { - $this->assignRoleToUser($sUserUID, $sRolCode); - } - return $sUserUID; - } - - /** - * updated an user - * - * @access public - * @param array $aData - * @param string $sRolCode - * @return void - */ - function updateUser($aData = array(), $sRolCode = '') { - if (isset($aData['USR_STATUS'])) { - if ($aData['USR_STATUS'] == 'ACTIVE') { - $aData['USR_STATUS'] = 1; - } - } - $this->userObj->update($aData); - if ($sRolCode != '') { - $this->removeRolesFromUser($aData['USR_UID']); - $this->assignRoleToUser($aData['USR_UID'], $sRolCode); - } - } - - /** - * to put role an user - * - * @access public - * @param string $sUserUID - * @param string $sRolCode - * @return void - */ - function assignRoleToUser($sUserUID = '', $sRolCode = '') { - $aRol = $this->rolesObj->loadByCode($sRolCode); - $this->usersRolesObj->create($sUserUID, $aRol['ROL_UID']); - } - - /** - * remove a role from an user - * - * @access public - * @param array $sUserUID - * @return void - */ - function removeRolesFromUser($sUserUID = '') { - $oCriteria = new Criteria('rbac'); - $oCriteria->add(UsersRolesPeer::USR_UID, $sUserUID); - UsersRolesPeer::doDelete($oCriteria); - } - - /** - * change status of an user - * - * @access public - * @param array $sUserUID - * @return void - */ - function changeUserStatus($sUserUID = '', $sStatus = 'ACTIVE') { - if ($sStatus == 'ACTIVE') { - $sStatus = 1; - } - - $aFields = $this->userObj->load($sUserUID); - $aFields['USR_STATUS'] = $sStatus; - $this->userObj->update($aFields); - } - - /** - * remove an user - * - * @access public - * @param array $sUserUID - * @return void - */ - function removeUser($sUserUID = '') { - $this->userObj->remove($sUserUID); - $this->removeRolesFromUser($sUserUID); - } - // - - - /** - * getting user's basic information (rbac) - * - * getting datas that is saved in rbac - * - * @author Fernando Ontiveros Lira - * @access public - - * @param string $uid id user - * @return array with info of an user - */ - function load ($uid ){ - $this->initRBAC(); - $this->userObj->Fields = $this->userObj->load($uid); - - $fieldsSystem = $this->systemObj->loadByCode($this->sSystem); - $fieldsRoles = $this->usersRolesObj->getRolesBySystem ($fieldsSystem['SYS_UID'], $uid ); - $this->userObj->Fields['USR_ROLE'] = $fieldsRoles['ROL_CODE']; - return $this->userObj->Fields; - } - - /** - * loading permission by code - * - * - * @access public - - * @param string $sCode - * @return void - */ -// function loadPermissionByCode($sCode) { -// return $this->permissionsObj->loadByCode($sCode); -// } - - /** - * create permission - * - * - * @access public - - * @param string $sCode - * @return void - */ - function createPermision($sCode) { - return $this->permissionsObj->create(array('PER_CODE' => $sCode)); - } - - /** - * loading role by code - * - * - * @access public - - * @param string $sCode - * @return void - */ -// function loadRoleByCode($sCode) { -// return $this->rolesObj->loadByCode($sCode); -// } - - /** - * list all roles - * - * - * @access public - - * @param string $systemCode - * @return $this->rolesObj - */ - - function listAllRoles ( $systemCode = 'PROCESSMAKER') { - return $this->rolesObj->listAllRoles($systemCode); - } - - /** - * getting all roles - * - * - * @access public - - * @param string $systemCode - * @return $this->rolesObj->getAllRoles - */ - function getAllRoles ( $systemCode = 'PROCESSMAKER') { - return $this->rolesObj->getAllRoles($systemCode); - } - -/** - * getting all roles by filter - * - * - * @access public - * @param string $filter - * @return $this->rolesObj->getAllRolesFilter - */ - function getAllRolesFilter ($start,$limit,$filter) { - return $this->rolesObj->getAllRolesFilter($start,$limit,$filter); - } - - /** - * list all permission - * - * - * @access public - - * @param string $systemCode - * @return $this->rolesObj->listAllPermissions - */ - function listAllPermissions ( $systemCode = 'PROCESSMAKER') { - return $this->rolesObj->listAllPermissions($systemCode); - } - - /** - * this function creates a role - * - * - * @access public - - * @param array $aData - * @return $this->rolesObj->createRole - */ - function createRole($aData) { - return $this->rolesObj->createRole($aData); - } - - /** - * this function removes a role - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->removeRole - */ - function removeRole($ROL_UID){ - return $this->rolesObj->removeRole($ROL_UID); - } - - /** - * this function checks a new role - * - * - * @access public - - * @param string $code - * @return $this->rolesObj->verifyNewRole - */ - function verifyNewRole($code){ - return $this->rolesObj->verifyNewRole($code); - } - - /** - * this function updates a role - * - * - * @access public - - * @param string $fields - * @return $this->rolesObj->updateRole - */ - function updateRole($fields){ - return $this->rolesObj->updateRole($fields); - } - - /** - * this function loads by ID - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->loadById - */ - function loadById($ROL_UID){ - return $this->rolesObj->loadById($ROL_UID); - } - - /** - * this function gets the user's roles - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->getRoleUsers - */ - function getRoleUsers($ROL_UID,$filter=''){ - return $this->rolesObj->getRoleUsers($ROL_UID,$filter); - } - -/** - * this function gets the number of users by roles - * - * - * @access public - * @author: Enrique Ponce de Leon - * - * @return $this->rolesObj->getAllUsersByRole - */ - function getAllUsersByRole(){ - return $this->rolesObj->getAllUsersByRole(); - } - -/** - * this function gets the number of users by department - * - * - * @access public - * @author: Enrique Ponce de Leon - * - * @return $this->rolesObj->getAllUsersByRole - */ - function getAllUsersByDepartment(){ - return $this->rolesObj->getAllUsersByDepartment(); - } - - /** - * this function gets roles code - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->getRoleCode - */ - function getRoleCode($ROL_UID){ - return $this->rolesObj->getRoleCode($ROL_UID); - } - - /** - * this function removes role from an user - * - * - * @access public - - * @param string $ROL_UID - * @param string $USR_UID - * @return $this->rolesObj->deleteUserRole - */ - function deleteUserRole($ROL_UID, $USR_UID){ - return $this->rolesObj->deleteUserRole($ROL_UID, $USR_UID); - } - - /** - * this function gets all user - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->getAllUsers - */ - function getAllUsers($ROL_UID, $filter=''){ - return $this->rolesObj->getAllUsers($ROL_UID,$filter); - } - - /** - * this function assigns role an user - * - * - * @access public - - * @param array $aData - * @return $this->rolesObj->assignUserToRole - */ - function assignUserToRole($aData){ - return $this->rolesObj->assignUserToRole($aData); - } - - /** - * this function gets role permission - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->getRolePermissions - */ - function getRolePermissions($ROL_UID, $filter='', $status=null){ - return $this->rolesObj->getRolePermissions($ROL_UID, $filter, $status); - } - - /** - * this function gets all permissions - * - * - * @access public - - * @param string $ROL_UID - * @param string $PER_SYSTEM - * @return $this->rolesObj->getAllPermissions - */ - function getAllPermissions($ROL_UID, $PER_SYSTEM="", $filter='', $status=null){ - return $this->rolesObj->getAllPermissions($ROL_UID, $PER_SYSTEM, $filter, $status); - } - - /** - * this function assigns permissions and role - * - * - * @access public - - * @param array $aData - * @return $this->rolesObj->assignPermissionRole - */ - function assignPermissionRole($sData){ - return $this->rolesObj->assignPermissionRole($sData); - } - - /** - * this function assigns permissions to a role - * - * - * @access public - - * @param string $sRoleUID - * @param string $sPermissionUID - * @return $this->rolesPermissionsObj->create - */ - function assignPermissionToRole($sRoleUID, $sPermissionUID) { - return $this->rolesPermissionsObj->create(array('ROL_UID' => $sRoleUID, 'PER_UID' => $sPermissionUID)); - } - - - /** - * this function removes permission to role - * - * - * @access public - - * @param string $ROL_UID - * @param string $PER_UID - * @return $this->rolesObj->deletePermissionRole - */ - function deletePermissionRole($ROL_UID, $PER_UID){ - return $this->rolesObj->deletePermissionRole($ROL_UID, $PER_UID); - } - - /** - * this function counts number of user without role - * - * - * @access public - - * @param string $ROL_UID - * @return $this->rolesObj->numUsersWithRole - */ - function numUsersWithRole($ROL_UID){ - return $this->rolesObj->numUsersWithRole($ROL_UID); - } - - /** - * this function creates system code - * - * - * @access public - - * @param string $sCode - * @return $this->systemObj->create - */ - function createSystem($sCode) { - return $this->systemObj->create(array('SYS_CODE' => $sCode)); - } - - /** - * this function checks by code - * - * - * @access public - - * @param string $sCode - * @return $this->rolesObj->verifyByCode - */ - function verifyByCode($sCode) { - return $this->rolesObj->verifyByCode($sCode); - } - - /** - * this function gets all authentication source - * Authentication Sources - * - * @access public - - * @param void - * @return $this->authSourcesObj->getAllAuthSources() - */ - - function getAllAuthSources() { - return $this->authSourcesObj->getAllAuthSources(); - } - -/** - * this function gets all authentication source - * Authentication Sources By User - * - * @access public - * @author Enrique Ponce de Leon - * @param void - * @return $this->authSourcesObj->getAllAuthSources() - */ - - function getAllAuthSourcesByUser() { - return $this->authSourcesObj->getAllAuthSourcesByUser(); - } - -/** - * this function gets all authentication source - * Authentication Sources based at parameters - * - * @access public - * @author Enrique Ponce de Leon - * @param int $start offset value to paging grid - * @param int $limit limit value to paging grid - * @param string $filter value to search or filter select - * @return $this->authSourcesObj->getAuthenticationSources() - */ - - function getAuthenticationSources($start,$limit,$filter='') { - return $this->authSourcesObj->getAuthenticationSources($start,$limit,$filter); - } - /** - * this function gets all authentication source - * Authentication Sources - * - * @access public - - * @param string $sUID - * @return $this->authSourcesObj->load - */ - function getAuthSource($sUID) { - $data = $this->authSourcesObj->load($sUID); - $pass =explode("_",$data['AUTH_SOURCE_PASSWORD']); - foreach($pass as $index => $value) { - if($value == '2NnV3ujj3w'){ - $data['AUTH_SOURCE_PASSWORD'] = G::decrypt($pass[0],$data['AUTH_SOURCE_SERVER_NAME']); - } - } - $this->authSourcesObj->Fields = $data; - return $this->authSourcesObj->Fields; - } - /** - * this function creates an authentication source - * Authentication Sources - * - * @access public - - * @param array $aData - * @return $this->authSourcesObj->create - */ - function createAuthSource($aData) { - $aData['AUTH_SOURCE_PASSWORD'] = G::encrypt($aData['AUTH_SOURCE_PASSWORD'],$aData['AUTH_SOURCE_SERVER_NAME'])."_2NnV3ujj3w"; - $this->authSourcesObj->create($aData); - } - - - /** - * this function updates an authentication source - * Authentication Sources - * - * @access public - - * @param array $aData - * @return $this->authSourcesObj->create - */ - function updateAuthSource($aData) { - $aData['AUTH_SOURCE_PASSWORD'] = G::encrypt($aData['AUTH_SOURCE_PASSWORD'],$aData['AUTH_SOURCE_SERVER_NAME'])."_2NnV3ujj3w"; - $this->authSourcesObj->update($aData); - } - - /** - * this function removes an authentication source - * Authentication Sources - * - * @access public - - * @param string $sUID - * @return $this->authSourcesObj->remove - */ - function removeAuthSource($sUID) { - $this->authSourcesObj->remove($sUID); - } - - /** - * this function gets all users by authentication source - * - * @access public - - * @param void - * @return $this->userObj->getAllUsersByAuthSource() - */ - - function getAllUsersByAuthSource(){ - return $this->userObj->getAllUsersByAuthSource(); - } - - /** - * this function gets all users by authentication source - * - * @access public - - * @param void - * @return $this->userObj->getAllUsersByAuthSource() - */ - - function getListUsersByAuthSource($aSource){ - return $this->userObj->getListUsersByAuthSource($aSource); - } - - /** - * this function searchs users - * - * - * @access public - - * @param string $sUID - * @param string $sKeyword - * @return array - */ - function searchUsers($sUID, $sKeyword) { - $aAuthSource = $this->getAuthSource($sUID); - $sAuthType = strtolower($aAuthSource['AUTH_SOURCE_PROVIDER']); - foreach ( $this->aRbacPlugins as $sClassName) { - if ( strtolower($sClassName) == $sAuthType ) { - $plugin = new $sClassName(); - $plugin->sAuthSource = $sUID; - $plugin->sSystem = $this->sSystem; - return $plugin->searchUsers($sKeyword); - } - } - return array(); - } - - - function requirePermissions($permissions){ - $numPerms = func_num_args(); - $permissions = func_get_args(); - - $access = -1; - - if ( $numPerms == 1 ){ - $access = $this->userCanAccess($permissions[0]); - } else if ( $numPerms > 0 ){ - foreach ($permissions as $perm) { - $access = $this->userCanAccess($perm); - if( $access == 1 ) { - $access = 1; - break; - } - } - } else { - throw new Exception('function requirePermissions() ->ERROR: Parameters missing!'); - } - - - if( $access == 1 ) - return true; - else { - switch ($access) { - case -2: - G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels'); - G::header('location: ../login/login'); - break; - case -1: - default: - G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels'); - G::header('location: ../login/login'); - break; - } - exit(0); - } - } - -private function getAllFiles($directory, $recursive = true ) { - $result = array(); - if (is_dir($directory)) + /** + * Gets the roles and permission for one RBAC_user + * + * gets the Role and their permissions for one User + * + * @author Fernando Ontiveros Lira + * @access public + * + * @param string $sSystem the system + * @param string $sUser the user + * @return $this->aUserInfo[ $sSystem ] + */ + public function loadUserRolePermission ($sSystem, $sUser) { - $handle = opendir($directory); - while ($datei = readdir($handle)) - { - if (($datei != '.') && ($datei != '..')) - { - $file = $directory.$datei; - if (is_dir($file)) { - if ($recursive) { - $result = array_merge($result, getAllFiles($file.'/')); - } - } else { - $result[] = $file; - } - } - } - closedir($handle); + //in previous versions we provided a path data and session we will cache the session Info for this user + //now this is deprecated, and all the aUserInfo is in the memcache + $this->sSystem = $sSystem; + $fieldsSystem = $this->systemObj->loadByCode( $sSystem ); + $fieldsRoles = $this->usersRolesObj->getRolesBySystem( $fieldsSystem['SYS_UID'], $sUser ); + $fieldsPermissions = $this->usersRolesObj->getAllPermissions( $fieldsRoles['ROL_UID'], $sUser ); + $this->aUserInfo['USER_INFO'] = $this->userObj->load( $sUser ); + $this->aUserInfo[$sSystem]['SYS_UID'] = $fieldsSystem['SYS_UID']; + $this->aUserInfo[$sSystem]['ROLE'] = $fieldsRoles; + $this->aUserInfo[$sSystem]['PERMISSIONS'] = $fieldsPermissions; + } + + /** + * verification the register automatic + * + * + * @access public + * @param string $strUser the system + * @param string $strPass the password + * @return $res + */ + public function checkAutomaticRegister ($strUser, $strPass) + { + $result = - 1; //default return value, + + + foreach ($this->aRbacPlugins as $sClassName) { + $plugin = new $sClassName(); + if (method_exists( $plugin, 'automaticRegister' )) { + $oCriteria = new Criteria( 'rbac' ); + $oCriteria->add( AuthenticationSourcePeer::AUTH_SOURCE_PROVIDER, $sClassName ); + $oCriteria->addAscendingOrderByColumn( AuthenticationSourcePeer::AUTH_SOURCE_NAME ); + $oDataset = AuthenticationSourcePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aRow = $oDataset->getRow(); + while (is_array( $aRow )) { + $aRow = array_merge( $aRow, unserialize( $aRow['AUTH_SOURCE_DATA'] ) ); + //Check if this authsource is enabled for AutoRegister, if not skip this + if ($aRow['AUTH_SOURCE_AUTO_REGISTER'] == 1) { + $plugin->sAuthSource = $aRow['AUTH_SOURCE_UID']; + $plugin->sSystem = $this->sSystem; + //search the usersRolesObj + //create the users in ProcessMaker + $res = $plugin->automaticRegister( $aRow, $strUser, $strPass ); + if ($res == 1) { + return $res; + } + } + $oDataset->next(); + $aRow = $oDataset->getRow(); + } + } + } + + } + + /** + * this function is checking the register automatic without authentication + * + * + * @access public + * @param string $sAuthType + * @param string $sAuthSource + * @param string $aUserFields + * @param string $sAuthUserDn + * @param string $strPass + * @return number -2: wrong password + * -3: inactive user + * -4: due date + * -5: invalid authentication source + */ + public function VerifyWithOtherAuthenticationSource ($sAuthType, $aUserFields, $strPass) + { + //check if the user is active + if ($aUserFields['USR_STATUS'] != 1) { + return - 3; //inactive user + } + + //check if the user's due date is valid + if ($aUserFields['USR_DUE_DATE'] < date( 'Y-m-d' )) { + return - 4; //due date + } + + + foreach ($this->aRbacPlugins as $sClassName) { + if (strtolower( $sClassName ) == strtolower( $sAuthType )) { + $plugin = new $sClassName(); + $plugin->sAuthSource = $aUserFields["UID_AUTH_SOURCE"]; + $plugin->sSystem = $this->sSystem; + $bValidUser = $plugin->VerifyLogin( $aUserFields["USR_AUTH_USER_DN"], $strPass ); + + if ($bValidUser === true) { + return ($aUserFields['USR_UID']); + } else { + return - 2; //wrong password + } + } + } + return - 5; //invalid authentication source + } + + /** + * authentication of an user through of class RBAC_user + * + * checking that an user has right to start an applicaton + * + * @author Fernando Ontiveros Lira + * @access public + * + * @param string $strUser UserId (login) an user + * @param string $strPass Password + * @return -1: no user + * -2: wrong password + * -3: inactive usuario + * -4: due date + * -5: invalid authentication source ( **new ) + * n : uid of user + */ + public function VerifyLogin ($strUser, $strPass) + { + if (strlen( $strPass ) == 0) { + return - 2; + } + //check if the user exists in the table RB_WORKFLOW.USERS + $this->initRBAC(); + //if the user exists, the VerifyUser function will return the user properties + if ($this->userObj->verifyUser( $strUser ) == 0) { + //here we are checking if the automatic user Register is enabled, ioc return -1 + $res = $this->checkAutomaticRegister( $strUser, $strPass ); + if ($res == 1) { + $this->userObj->verifyUser( $strUser ); + } else { + return $res; + } + } + + //default values + $sAuthType = 'mysql'; + if (isset( $this->userObj->fields['USR_AUTH_TYPE'] )) { + $sAuthType = strtolower( $this->userObj->fields['USR_AUTH_TYPE'] ); + } + + //Hook for RBAC plugins + if ($sAuthType != "mysql" && $sAuthType != "") { + $res = $this->VerifyWithOtherAuthenticationSource( $sAuthType, $this->userObj->fields, $strPass ); + return $res; + } else { + $this->userObj->reuseUserFields = true; + $res = $this->userObj->VerifyLogin( $strUser, $strPass ); + return $res; + } + } + + /** + * Verify if the user exist or not exists, the argument is the UserName + * + * @author Everth S. Berrios + * @access public + * @param string $strUser + * @return $res + */ + public function verifyUser ($strUser) + { + $res = $this->userObj->verifyUser( $strUser ); + return $res; + } + + /** + * Verify if the user exist or not exists, the argument is the UserUID + * + * @author Everth S. Berrios + * @access public + * @param string $strUserId + * @return $res + */ + public function verifyUserId ($strUserId) + { + $res = $this->userObj->verifyUserId( $strUserId ); + return $res; + } + + /** + * Verify if the user has a right over the permission + * + * @author Fernando Ontiveros + * @access public + * + * @param string $uid id of user + * @param string $system Code of System + * @param string $perm id of Permissions + * @return 1: If it is ok + * -1: System doesn't exists + * -2: The User has not a Role + * -3: The User has not this Permission. + */ + public function userCanAccess ($perm) + { + if (isset( $this->aUserInfo[$this->sSystem]['PERMISSIONS'] )) { + $res = - 3; + //if ( !isset ( $this->aUserInfo[ $this->sSystem ]['ROLE'. 'x'] ) ) $res = -2; + foreach ($this->aUserInfo[$this->sSystem]['PERMISSIONS'] as $key => $val) { + if ($perm == $val['PER_CODE']) { + $res = 1; + } + } + } else { + $res = - 1; + } + + return $res; + } + + /** + * to create an user + * + * @access public + * @param array $aData + * @param string $sRolCode + * @return $sUserUID + */ + public function createUser ($aData = array(), $sRolCode = '') + { + if ($aData['USR_STATUS'] == 'ACTIVE') { + $aData['USR_STATUS'] = 1; + } + if ($aData['USR_STATUS'] == 'INACTIVE') { + $aData['USR_STATUS'] = 0; + } + $sUserUID = $this->userObj->create( $aData ); + if ($sRolCode != '') { + $this->assignRoleToUser( $sUserUID, $sRolCode ); + } + return $sUserUID; + } + + /** + * updated an user + * + * @access public + * @param array $aData + * @param string $sRolCode + * @return void + */ + public function updateUser ($aData = array(), $sRolCode = '') + { + if (isset( $aData['USR_STATUS'] )) { + if ($aData['USR_STATUS'] == 'ACTIVE') { + $aData['USR_STATUS'] = 1; + } + } + $this->userObj->update( $aData ); + if ($sRolCode != '') { + $this->removeRolesFromUser( $aData['USR_UID'] ); + $this->assignRoleToUser( $aData['USR_UID'], $sRolCode ); + } + } + + /** + * to put role an user + * + * @access public + * @param string $sUserUID + * @param string $sRolCode + * @return void + */ + public function assignRoleToUser ($sUserUID = '', $sRolCode = '') + { + $aRol = $this->rolesObj->loadByCode( $sRolCode ); + $this->usersRolesObj->create( $sUserUID, $aRol['ROL_UID'] ); + } + + /** + * remove a role from an user + * + * @access public + * @param array $sUserUID + * @return void + */ + public function removeRolesFromUser ($sUserUID = '') + { + $oCriteria = new Criteria( 'rbac' ); + $oCriteria->add( UsersRolesPeer::USR_UID, $sUserUID ); + UsersRolesPeer::doDelete( $oCriteria ); + } + + /** + * change status of an user + * + * @access public + * @param array $sUserUID + * @return void + */ + public function changeUserStatus ($sUserUID = '', $sStatus = 'ACTIVE') + { + if ($sStatus == 'ACTIVE') { + $sStatus = 1; + } + + $aFields = $this->userObj->load( $sUserUID ); + $aFields['USR_STATUS'] = $sStatus; + $this->userObj->update( $aFields ); + } + + /** + * remove an user + * + * @access public + * @param array $sUserUID + * @return void + */ + public function removeUser ($sUserUID = '') + { + $this->userObj->remove( $sUserUID ); + $this->removeRolesFromUser( $sUserUID ); + } + // + + + /** + * getting user's basic information (rbac) + * + * getting datas that is saved in rbac + * + * @author Fernando Ontiveros Lira + * @access public + * + * @param string $uid id user + * @return array with info of an user + */ + public function load ($uid) + { + $this->initRBAC(); + $this->userObj->Fields = $this->userObj->load( $uid ); + + $fieldsSystem = $this->systemObj->loadByCode( $this->sSystem ); + $fieldsRoles = $this->usersRolesObj->getRolesBySystem( $fieldsSystem['SYS_UID'], $uid ); + $this->userObj->Fields['USR_ROLE'] = $fieldsRoles['ROL_CODE']; + return $this->userObj->Fields; + } + + /** + * loading permission by code + * + * + * @access public + * + * @param string $sCode + * @return void + */ + // function loadPermissionByCode($sCode) { + // return $this->permissionsObj->loadByCode($sCode); + // } + + + /** + * create permission + * + * + * @access public + * + * @param string $sCode + * @return void + */ + public function createPermision ($sCode) + { + return $this->permissionsObj->create( array ('PER_CODE' => $sCode + ) ); + } + + /** + * loading role by code + * + * + * @access public + * + * @param string $sCode + * @return void + */ + // function loadRoleByCode($sCode) { + // return $this->rolesObj->loadByCode($sCode); + // } + + + /** + * list all roles + * + * + * @access public + * + * @param string $systemCode + * @return $this->rolesObj + */ + + public function listAllRoles ($systemCode = 'PROCESSMAKER') + { + return $this->rolesObj->listAllRoles( $systemCode ); + } + + /** + * getting all roles + * + * + * @access public + * + * @param string $systemCode + * @return $this->rolesObj->getAllRoles + */ + public function getAllRoles ($systemCode = 'PROCESSMAKER') + { + return $this->rolesObj->getAllRoles( $systemCode ); + } + + /** + * getting all roles by filter + * + * + * @access public + * @param string $filter + * @return $this->rolesObj->getAllRolesFilter + */ + public function getAllRolesFilter ($start, $limit, $filter) + { + return $this->rolesObj->getAllRolesFilter( $start, $limit, $filter ); + } + + /** + * list all permission + * + * + * @access public + * + * @param string $systemCode + * @return $this->rolesObj->listAllPermissions + */ + public function listAllPermissions ($systemCode = 'PROCESSMAKER') + { + return $this->rolesObj->listAllPermissions( $systemCode ); + } + + /** + * this function creates a role + * + * + * @access public + * + * @param array $aData + * @return $this->rolesObj->createRole + */ + public function createRole ($aData) + { + return $this->rolesObj->createRole( $aData ); + } + + /** + * this function removes a role + * + * + * @access public + * + * @param string $ROL_UID + * $@return $this->rolesObj->removeRole + */ + public function removeRole ($ROL_UID) + { + return $this->rolesObj->removeRole( $ROL_UID ); + } + + /** + * this function checks a new role + * + * + * @access public + * + * @param string $code + * @return $this->rolesObj->verifyNewRole + */ + public function verifyNewRole ($code) + { + return $this->rolesObj->verifyNewRole( $code ); + } + + /** + * this function updates a role + * + * + * @access public + * + * @param string $fields + * @return $this->rolesObj->updateRole + */ + public function updateRole ($fields) + { + return $this->rolesObj->updateRole( $fields ); + } + + /** + * this function loads by ID + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->loadById + */ + public function loadById ($ROL_UID) + { + return $this->rolesObj->loadById( $ROL_UID ); + } + + /** + * this function gets the user's roles + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->getRoleUsers + */ + public function getRoleUsers ($ROL_UID, $filter = '') + { + return $this->rolesObj->getRoleUsers( $ROL_UID, $filter ); + } + + /** + * this function gets the number of users by roles + * + * + * @access public + * @author : Enrique Ponce de Leon + * + * @return $this->rolesObj->getAllUsersByRole + */ + public function getAllUsersByRole () + { + return $this->rolesObj->getAllUsersByRole(); + } + + /** + * this function gets the number of users by department + * + * + * @access public + * @author : Enrique Ponce de Leon + * + * @return $this->rolesObj->getAllUsersByRole + */ + public function getAllUsersByDepartment () + { + return $this->rolesObj->getAllUsersByDepartment(); + } + + /** + * this function gets roles code + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->getRoleCode + */ + public function getRoleCode ($ROL_UID) + { + return $this->rolesObj->getRoleCode( $ROL_UID ); + } + + /** + * this function removes role from an user + * + * + * @access public + * + * @param string $ROL_UID + * @param string $USR_UID + * @return $this->rolesObj->deleteUserRole + */ + public function deleteUserRole ($ROL_UID, $USR_UID) + { + return $this->rolesObj->deleteUserRole( $ROL_UID, $USR_UID ); + } + + /** + * this function gets all user + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->getAllUsers + */ + public function getAllUsers ($ROL_UID, $filter = '') + { + return $this->rolesObj->getAllUsers( $ROL_UID, $filter ); + } + + /** + * this function assigns role an user + * + * + * @access public + * + * @param array $aData + * @return $this->rolesObj->assignUserToRole + */ + public function assignUserToRole ($aData) + { + return $this->rolesObj->assignUserToRole( $aData ); + } + + /** + * this function gets role permission + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->getRolePermissions + */ + public function getRolePermissions ($ROL_UID, $filter = '', $status = null) + { + return $this->rolesObj->getRolePermissions( $ROL_UID, $filter, $status ); + } + + /** + * this function gets all permissions + * + * + * @access public + * + * @param string $ROL_UID + * @param string $PER_SYSTEM + * @return $this->rolesObj->getAllPermissions + */ + public function getAllPermissions ($ROL_UID, $PER_SYSTEM = "", $filter = '', $status = null) + { + return $this->rolesObj->getAllPermissions( $ROL_UID, $PER_SYSTEM, $filter, $status ); + } + + /** + * this function assigns permissions and role + * + * + * @access public + * + * @param array $aData + * @return $this->rolesObj->assignPermissionRole + */ + public function assignPermissionRole ($sData) + { + return $this->rolesObj->assignPermissionRole( $sData ); + } + + /** + * this function assigns permissions to a role + * + * + * @access public + * + * @param string $sRoleUID + * @param string $sPermissionUID + * @return $this->rolesPermissionsObj->create + */ + public function assignPermissionToRole ($sRoleUID, $sPermissionUID) + { + return $this->rolesPermissionsObj->create( array ('ROL_UID' => $sRoleUID,'PER_UID' => $sPermissionUID ) ); + } + + /** + * this function removes permission to role + * + * + * @access public + * + * @param string $ROL_UID + * @param string $PER_UID + * @return $this->rolesObj->deletePermissionRole + */ + public function deletePermissionRole ($ROL_UID, $PER_UID) + { + return $this->rolesObj->deletePermissionRole( $ROL_UID, $PER_UID ); + } + + /** + * this function counts number of user without role + * + * + * @access public + * + * @param string $ROL_UID + * @return $this->rolesObj->numUsersWithRole + */ + public function numUsersWithRole ($ROL_UID) + { + return $this->rolesObj->numUsersWithRole( $ROL_UID ); + } + + /** + * this function creates system code + * + * + * @access public + * + * @param string $sCode + * @return $this->systemObj->create + */ + public function createSystem ($sCode) + { + return $this->systemObj->create( array ('SYS_CODE' => $sCode + ) ); + } + + /** + * this function checks by code + * + * + * @access public + * + * @param string $sCode + * @return $this->rolesObj->verifyByCode + */ + public function verifyByCode ($sCode) + { + return $this->rolesObj->verifyByCode( $sCode ); + } + + /** + * this function gets all authentication source + * Authentication Sources + * + * @access public + * + * @param void + * @return $this->authSourcesObj->getAllAuthSources() + */ + + public function getAllAuthSources () + { + return $this->authSourcesObj->getAllAuthSources(); + } + + /** + * this function gets all authentication source + * Authentication Sources By User + * + * @access public + * @author Enrique Ponce de Leon + * @param void + * @return $this->authSourcesObj->getAllAuthSources() + */ + + public function getAllAuthSourcesByUser () + { + return $this->authSourcesObj->getAllAuthSourcesByUser(); + } + + /** + * this function gets all authentication source + * Authentication Sources based at parameters + * + * @access public + * @author Enrique Ponce de Leon + * @param int $start offset value to paging grid + * @param int $limit limit value to paging grid + * @param string $filter value to search or filter select + * @return $this->authSourcesObj->getAuthenticationSources() + */ + + public function getAuthenticationSources ($start, $limit, $filter = '') + { + return $this->authSourcesObj->getAuthenticationSources( $start, $limit, $filter ); + } + + /** + * this function gets all authentication source + * Authentication Sources + * + * @access public + * + * @param string $sUID + * @return $this->authSourcesObj->load + */ + public function getAuthSource ($sUID) + { + $data = $this->authSourcesObj->load( $sUID ); + $pass = explode( "_", $data['AUTH_SOURCE_PASSWORD'] ); + foreach ($pass as $index => $value) { + if ($value == '2NnV3ujj3w') { + $data['AUTH_SOURCE_PASSWORD'] = G::decrypt( $pass[0], $data['AUTH_SOURCE_SERVER_NAME'] ); + } + } + $this->authSourcesObj->Fields = $data; + return $this->authSourcesObj->Fields; + } + + /** + * this function creates an authentication source + * Authentication Sources + * + * @access public + * + * @param array $aData + * @return $this->authSourcesObj->create + */ + public function createAuthSource ($aData) + { + $aData['AUTH_SOURCE_PASSWORD'] = G::encrypt( $aData['AUTH_SOURCE_PASSWORD'], $aData['AUTH_SOURCE_SERVER_NAME'] ) . "_2NnV3ujj3w"; + $this->authSourcesObj->create( $aData ); + } + + /** + * this function updates an authentication source + * Authentication Sources + * + * @access public + * + * @param array $aData + * @return $this->authSourcesObj->create + */ + public function updateAuthSource ($aData) + { + $aData['AUTH_SOURCE_PASSWORD'] = G::encrypt( $aData['AUTH_SOURCE_PASSWORD'], $aData['AUTH_SOURCE_SERVER_NAME'] ) . "_2NnV3ujj3w"; + $this->authSourcesObj->update( $aData ); + } + + /** + * this function removes an authentication source + * Authentication Sources + * + * @access public + * + * @param string $sUID + * @return $this->authSourcesObj->remove + */ + public function removeAuthSource ($sUID) + { + $this->authSourcesObj->remove( $sUID ); + } + + /** + * this function gets all users by authentication source + * + * @access public + * + * @param void + * @return $this->userObj->getAllUsersByAuthSource() + */ + + public function getAllUsersByAuthSource () + { + return $this->userObj->getAllUsersByAuthSource(); + } + + /** + * this function gets all users by authentication source + * + * @access public + * + * @param void + * @return $this->userObj->getAllUsersByAuthSource() + */ + + public function getListUsersByAuthSource ($aSource) + { + return $this->userObj->getListUsersByAuthSource( $aSource ); + } + + /** + * this function searchs users + * + * + * @access public + * + * @param string $sUID + * @param string $sKeyword + * @return array + */ + public function searchUsers ($sUID, $sKeyword) + { + $aAuthSource = $this->getAuthSource( $sUID ); + $sAuthType = strtolower( $aAuthSource['AUTH_SOURCE_PROVIDER'] ); + foreach ($this->aRbacPlugins as $sClassName) { + if (strtolower( $sClassName ) == $sAuthType) { + $plugin = new $sClassName(); + $plugin->sAuthSource = $sUID; + $plugin->sSystem = $this->sSystem; + return $plugin->searchUsers( $sKeyword ); + } + } + return array (); + } + + public function requirePermissions ($permissions) + { + $numPerms = func_num_args(); + $permissions = func_get_args(); + + $access = - 1; + + if ($numPerms == 1) { + $access = $this->userCanAccess( $permissions[0] ); + } elseif ($numPerms > 0) { + foreach ($permissions as $perm) { + $access = $this->userCanAccess( $perm ); + if ($access == 1) { + $access = 1; + break; + } + } + } else { + throw new Exception( 'function requirePermissions() ->ERROR: Parameters missing!' ); + } + + if ($access == 1) { + return true; + } else { + switch ($access) { + case - 2: + G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels' ); + G::header( 'location: ../login/login' ); + break; + case - 1: + default: + G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels' ); + G::header( 'location: ../login/login' ); + break; + } + exit( 0 ); + } + } + + private function getAllFiles ($directory, $recursive = true) + { + $result = array (); + if (is_dir( $directory )) { + $handle = opendir( $directory ); + while ($datei = readdir( $handle )) { + if (($datei != '.') && ($datei != '..')) { + $file = $directory . $datei; + if (is_dir( $file )) { + if ($recursive) { + $result = array_merge( $result, getAllFiles( $file . '/' ) ); + } + } else { + $result[] = $file; + } + } + } + closedir( $handle ); + } + return $result; + } + + private function getFilesTimestamp ($directory, $recursive = true) + { + $allFiles = self::getAllFiles( $directory, $recursive ); + $fileArray = array (); + foreach ($allFiles as $val) { + $timeResult['file'] = $val; + $timeResult['timestamp'] = filemtime( $val ); + $fileArray[] = $timeResult; + } + return $fileArray; + } + + public function cleanSessionFiles ($hours = 72) + { + $currentTime = strtotime( "now" ); + $timeDifference = $hours * 60 * 60; + $limitTime = $currentTime - $timeDifference; + $sessionsPath = PATH_DATA . 'session' . PATH_SEP; + $filesResult = self::getFilesTimestamp( $sessionsPath ); + $count = 0; + foreach ($filesResult as $file) { + if ($file['timestamp'] < $limitTime) { + unlink( $file['file'] ); + $count ++; + } + } } - return $result; } -private function getFilesTimestamp($directory, $recursive = true) { - $allFiles = self::getAllFiles($directory, $recursive); - $fileArray = array (); - foreach ($allFiles as $val) { - $timeResult['file'] = $val; - $timeResult['timestamp'] = filemtime($val); - $fileArray[] = $timeResult; - } - return $fileArray; -} - -public function cleanSessionFiles($hours = 72){ - $currentTime = strtotime("now"); - $timeDifference = $hours*60*60; - $limitTime = $currentTime - $timeDifference; - $sessionsPath = PATH_DATA.'session'.PATH_SEP; - $filesResult = self::getFilesTimestamp($sessionsPath); - $count = 0; - foreach ($filesResult as $file){ - if ( $file['timestamp'] < $limitTime ){ - unlink ($file['file']); - $count++; - } - } -} - - -} \ No newline at end of file diff --git a/gulliver/system/class.restClient.php b/gulliver/system/class.restClient.php index e99c37c2a..83442f496 100755 --- a/gulliver/system/class.restClient.php +++ b/gulliver/system/class.restClient.php @@ -3,317 +3,347 @@ /** * Class RestClient */ -class RestClient { +class RestClient +{ - private $curl ; - private $url ; - private $response =""; - private $headers = array(); + private $curl; + private $url; + private $response = ""; + private $headers = array (); - private $method="GET"; - private $params=null; - private $contentType = null; - private $file =null; + private $method = "GET"; + private $params = null; + private $contentType = null; + private $file = null; - /** - * Private Constructor, sets default options - */ - public function __construct() { - $this->curl = curl_init(); - curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true); - curl_setopt($this->curl,CURLOPT_AUTOREFERER,true); // This make sure will follow redirects - curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); // This too - curl_setopt($this->curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers - } + /** + * Private Constructor, sets default options + */ + public function __construct () + { + $this->curl = curl_init(); + curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $this->curl, CURLOPT_AUTOREFERER, true ); // This make sure will follow redirects + curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, true ); // This too + curl_setopt( $this->curl, CURLOPT_HEADER, true ); // THis verbose option for extracting the headers + } - /** - * Execute the call to the webservice - * @return RestClient - */ - public function execute() { - if($this->method === "POST") { - curl_setopt($this->curl,CURLOPT_POST,true); - curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->params); - //var_dump($this->params); - //die; - } else if($this->method == "GET"){ - curl_setopt($this->curl,CURLOPT_HTTPGET,true); - $this->treatURL(); - } else if($this->method === "PUT") { - curl_setopt($this->curl,CURLOPT_PUT,true); - $this->treatURL(); - $this->file = tmpFile(); - fwrite($this->file,$this->params); - fseek($this->file,0); - curl_setopt($this->curl,CURLOPT_INFILE,$this->file); - curl_setopt($this->curl,CURLOPT_INFILESIZE,strlen($this->params)); - } else { - curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$this->method); - } - if($this->contentType != null) { - curl_setopt($this->curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this->contentType, "SKEY: 8QRtY5zXyViZ9fjYou")); - } - curl_setopt($this->curl,CURLOPT_URL,$this->url); - $r = curl_exec($this->curl); - if($this->method !== "DELETE") - { - $this->treatResponse($r); // Extract the headers and response - return $this ; - } - else{ - return $this; - } + /** + * Execute the call to the webservice + * + * @return RestClient + */ + public function execute () + { + if ($this->method === "POST") { + curl_setopt( $this->curl, CURLOPT_POST, true ); + curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->params ); + //var_dump($this->params); + //die; + } elseif ($this->method == "GET") { + curl_setopt( $this->curl, CURLOPT_HTTPGET, true ); + $this->treatURL(); + } elseif ($this->method === "PUT") { + curl_setopt( $this->curl, CURLOPT_PUT, true ); + $this->treatURL(); + $this->file = tmpFile(); + fwrite( $this->file, $this->params ); + fseek( $this->file, 0 ); + curl_setopt( $this->curl, CURLOPT_INFILE, $this->file ); + curl_setopt( $this->curl, CURLOPT_INFILESIZE, strlen( $this->params ) ); + } else { + curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, $this->method ); + } + if ($this->contentType != null) { + curl_setopt( $this->curl, CURLOPT_HTTPHEADER, array ("Content-Type: " . $this->contentType,"SKEY: 8QRtY5zXyViZ9fjYou" ) ); + } + curl_setopt( $this->curl, CURLOPT_URL, $this->url ); + $r = curl_exec( $this->curl ); + if ($this->method !== "DELETE") { + $this->treatResponse( $r ); // Extract the headers and response + return $this; + } else { + return $this; + } + } - } - - /** - * Treats URL - */ - private function treatURL(){ - if(is_array($this->params) && count($this->params) >= 1) { // Transform parameters in key/value pars in URL - if(!strpos($this->url,'?')) - $this->url .= '?' ; - foreach($this->params as $k=>$v) { - $this->url .= "&".urlencode($k)."=".urlencode($v); - } - } + /** + * Treats URL + */ + private function treatURL () + { + if (is_array( $this->params ) && count( $this->params ) >= 1) { + // Transform parameters in key/value pars in URL + if (! strpos( $this->url, '?' )) { + $this->url .= '?'; + } + foreach ($this->params as $k => $v) { + $this->url .= "&" . urlencode( $k ) . "=" . urlencode( $v ); + } + } return $this->url; - } + } - /* + /* * Treats the Response for extracting the Headers and Response */ - private function treatResponse($r) { - if($r == null or strlen($r) < 1) { + private function treatResponse ($r) + { + if ($r == null or strlen( $r ) < 1) { return; } - $parts = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body - while(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0]) or preg_match("@Moved@",$parts[0])) { + $parts = explode( "\n\r", $r ); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body + while (preg_match( '@HTTP/1.[0-1] 100 Continue@', $parts[0] ) or preg_match( "@Moved@", $parts[0] )) { // Continue header must be bypass - for($i=1;$iheaders['content-type'] = $reg[1]; - preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message + preg_match( "@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@", $parts[0], $reg ); // This extracts the response header Code and Message $this->headers['code'] = $reg[1]; $this->headers['message'] = $reg[2]; $this->response = ""; - for($i=1;$i 1) { + for ($i = 1; $i < count( $parts ); $i ++) { + //This make sure that exploded response get back togheter + if ($i > 1) { $this->response .= "\n\r"; } $this->response .= $parts[$i]; } - } + } - /* + /* * @return array */ - public function getHeaders() { + public function getHeaders () + { return $this->headers; - } + } - /* + /* * @return string */ - public function getResponse() { - return $this->response ; - } + public function getResponse () + { + return $this->response; + } - /* + /* * HTTP response code (404,401,200,etc) * @return int */ - public function getResponseCode() { - return (int) $this->headers['code']; - } + public function getResponseCode () + { + return (int) $this->headers['code']; + } - /* + /* * HTTP response message (Not Found, Continue, etc ) * @return string */ - public function getResponseMessage() { - return $this->headers['message']; - } + public function getResponseMessage () + { + return $this->headers['message']; + } - /* + /* * Content-Type (text/plain, application/xml, etc) * @return string */ - public function getResponseContentType() { - return $this->headers['content-type']; - } + public function getResponseContentType () + { + return $this->headers['content-type']; + } - /** - * This sets that will not follow redirects - * @return RestClient - */ - public function setNoFollow() { - curl_setopt($this->curl,CURLOPT_AUTOREFERER,false); - curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false); - return $this; - } + /** + * This sets that will not follow redirects + * + * @return RestClient + */ + public function setNoFollow () + { + curl_setopt( $this->curl, CURLOPT_AUTOREFERER, false ); + curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, false ); + return $this; + } - /** - * This closes the connection and release resources - * @return RestClient - */ - public function close() { - curl_close($this->curl); - $this->curl = null ; - if($this->file !=null) { - fclose($this->file); - } - return $this ; - } + /** + * This closes the connection and release resources + * + * @return RestClient + */ + public function close () + { + curl_close( $this->curl ); + $this->curl = null; + if ($this->file != null) { + fclose( $this->file ); + } + return $this; + } - /** - * Sets the URL to be Called - * @return RestClient - */ - public function setUrl($url) { - $this->url = $url; - return $this; - } + /** + * Sets the URL to be Called + * + * @return RestClient + */ + public function setUrl ($url) + { + $this->url = $url; + return $this; + } - /** - * Set the Content-Type of the request to be send - * Format like "application/xml" or "text/plain" or other - * @param string $contentType - * @return RestClient - */ - public function setContentType($contentType) { - $this->contentType = $contentType; - return $this; - } + /** + * Set the Content-Type of the request to be send + * Format like "application/xml" or "text/plain" or other + * + * @param string $contentType + * @return RestClient + */ + public function setContentType ($contentType) + { + $this->contentType = $contentType; + return $this; + } - /** - * Set the Credentials for BASIC Authentication - * @param string $user - * @param string $pass - * @return RestClient - */ - public function setCredentials($user,$pass) { - if($user != null) { - curl_setopt($this->curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); - curl_setopt($this->curl,CURLOPT_USERPWD,"{$user}:{$pass}"); - } - return $this; - } + /** + * Set the Credentials for BASIC Authentication + * + * @param string $user + * @param string $pass + * @return RestClient + */ + public function setCredentials ($user, $pass) + { + if ($user != null) { + curl_setopt( $this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); + curl_setopt( $this->curl, CURLOPT_USERPWD, "{$user}:{$pass}" ); + } + return $this; + } - /** - * Set the Request HTTP Method - * For now, only accepts GET and POST - * @param string $method - * @return RestClient - */ - public function setMethod($method) { - $this->method=$method; - return $this; - } + /** + * Set the Request HTTP Method + * For now, only accepts GET and POST + * + * @param string $method + * @return RestClient + */ + public function setMethod ($method) + { + $this->method = $method; + return $this; + } - /** - * Set Parameters to be send on the request - * It can be both a key/value par array (as in array("key"=>"value")) - * or a string containing the body of the request, like a XML, JSON or other - * Proper content-type should be set for the body if not a array - * @param mixed $params - * @return RestClient - */ - public function setParameters($params) { - $this->params=$params; - return $this; - } + /** + * Set Parameters to be send on the request + * It can be both a key/value par array (as in array("key"=>"value")) + * or a string containing the body of the request, like a XML, JSON or other + * Proper content-type should be set for the body if not a array + * + * @param mixed $params + * @return RestClient + */ + public function setParameters ($params) + { + $this->params = $params; + return $this; + } - /** - * Creates the RESTClient - * @param string $url=null [optional] - * @return RestClient - */ - public static function createClient($url=null) { - $client = new RestClient ; - if($url != null) { - $client->setUrl($url); - } - return $client; - } + /** + * Creates the RESTClient + * + * @param string $url=null [optional] + * @return RestClient + */ + public static function createClient ($url = null) + { + $client = new RestClient(); + if ($url != null) { + $client->setUrl( $url ); + } + return $client; + } - /** - * Convenience method wrapping a commom POST call - * @param string $url - * @param mixed params - * @param string $user=null [optional] - * @param string $password=null [optional] - * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default - * @return RestClient - */ - //public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { - public static function post($url,$params,$user,$pwd,$contentType="multipart/form-data") { - //return self::call("POST",$url,$params,$user,$pwd,$contentType); - return self::call("POST",$url,$params,$user,$pwd,$contentType); - } + /** + * Convenience method wrapping a commom POST call + * + * @param string $url + * @param mixed params + * @param string $user=null [optional] + * @param string $password=null [optional] + * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default + * @return RestClient + */ + //public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { + public static function post ($url, $params, $user, $pwd, $contentType = "multipart/form-data") + { + //return self::call("POST",$url,$params,$user,$pwd,$contentType); + return self::call( "POST", $url, $params, $user, $pwd, $contentType ); + } - /** - * Convenience method wrapping a commom PUT call - * @param string $url - * @param string $body - * @param string $user=null [optional] - * @param string $password=null [optional] - * @param string $contentType=null [optional] - * @return RestClient - */ - public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { - return self::call("PUT",$url,$body,$user,$pwd,$contentType); - } + /** + * Convenience method wrapping a commom PUT call + * + * @param string $url + * @param string $body + * @param string $user=null [optional] + * @param string $password=null [optional] + * @param string $contentType=null [optional] + * @return RestClient + */ + public static function put ($url, $body, $user = null, $pwd = null, $contentType = null) + { + return self::call( "PUT", $url, $body, $user, $pwd, $contentType ); + } - /** - * Convenience method wrapping a commom GET call - * @param string $url - * @param array params - * @param string $user=null [optional] - * @param string $password=null [optional] - * @return RestClient - */ - //public static function get($url,array $params=null,$user=null,$pwd=null,$contentType=null) { - public static function get($url,$user,$pwd,$contentType=null) { - //return self::call("GET",$url,$params,$user,$pwd,$contentType); - return self::call("GET",$url,null,$user,$pwd,$contentType); - } + /** + * Convenience method wrapping a commom GET call + * + * @param string $url + * @param array params + * @param string $user=null [optional] + * @param string $password=null [optional] + * @return RestClient + */ + //public static function get($url,array $params=null,$user=null,$pwd=null,$contentType=null) { + public static function get ($url, $user, $pwd, $contentType = null) + { + //return self::call("GET",$url,$params,$user,$pwd,$contentType); + return self::call( "GET", $url, null, $user, $pwd, $contentType ); + } - /** - * Convenience method wrapping a commom delete call - * @param string $url - * @param array params - * @param string $user=null [optional] - * @param string $password=null [optional] - * @return RestClient - */ - public static function delete($url,$user=null,$pwd=null,$contentType=null) { - return self::call("DELETE",$url,null,$user,$pwd,$contentType); - } + /** + * Convenience method wrapping a commom delete call + * + * @param string $url + * @param array params + * @param string $user=null [optional] + * @param string $password=null [optional] + * @return RestClient + */ + public static function delete ($url, $user = null, $pwd = null, $contentType = null) + { + return self::call( "DELETE", $url, null, $user, $pwd, $contentType ); + } - /** - * Convenience method wrapping a commom custom call - * @param string $method - * @param string $url - * @param string $body - * @param string $user=null [optional] - * @param string $password=null [optional] - * @param string $contentType=null [optional] - * @return RestClient - */ - public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { - return self::createClient($url) - ->setParameters($body) - ->setMethod($method) - ->setCredentials($user,$pwd) - ->setContentType($contentType) - ->execute() - ->close(); - } + /** + * Convenience method wrapping a commom custom call + * + * @param string $method + * @param string $url + * @param string $body + * @param string $user=null [optional] + * @param string $password=null [optional] + * @param string $contentType=null [optional] + * @return RestClient + */ + public static function call ($method, $url, $body, $user = null, $pwd = null, $contentType = null) + { + return self::createClient( $url )->setParameters( $body )->setMethod( $method )->setCredentials( $user, $pwd )->setContentType( $contentType )->execute()->close(); + } } -?> \ No newline at end of file diff --git a/gulliver/system/class.ymlTestCases.php b/gulliver/system/class.ymlTestCases.php index 938cba39d..444406dbd 100755 --- a/gulliver/system/class.ymlTestCases.php +++ b/gulliver/system/class.ymlTestCases.php @@ -1,7 +1,9 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -41,235 +43,233 @@ * ... */ - /** +/** + * * @package gulliver.system */ class ymlTestCases { - var $testCaseFile; - var $testCases=array(); - - /** - * function TestCases - * - * @access public - * @param string $testCaseFile - * @param string $testDomain - * @param string $testLime - * @return void - */ - function ymlTestCases( $testCaseFile, &$testDomain, &$testLime ) - { - $this->testDomain =& $testDomain; - $this->testLime =& $testLime; - if (basename($testCaseFile)===$testCaseFile) - $testCaseFile = PATH_FIXTURES . $testCaseFile; - $this->testCaseFile=$testCaseFile; - } - - /** - * function load - * - * @access public - * @param string $inputTestCasesIndex - * @param array $fields - * @return array - */ - function load( $inputTestCasesIndex = 'TestCases', $fields=array() ) - { - $testCases=array(); - $input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile ); - foreach($input[$inputTestCasesIndex] as $preTestCase){ - $testFunctionInputs=array(); - foreach($preTestCase['Input'] as $inputArgument => $value ){ - if (substr($inputArgument,-2,2)==='[]'){ - //DOMAIN - $inputArgument=substr($inputArgument,0,strlen($inputArgument)-2); - if (!isset($testFunctionInputs[$inputArgument])) - $testFunctionInputs[$inputArgument]=array(); - //var_dump($this->testDomain->global,$this->testDomain->get( $value ), $value ); - ymlDomain::arrayAppend( - $testFunctionInputs[$inputArgument], - $this->testDomain->get( $value ) - ); - } - else{ - //SPECIFIC VALUE - if (!isset($testFunctionInputs[$inputArgument])){ - $testFunctionInputs[$inputArgument]=array(); - } - ymlDomain::arrayAppend( - $testFunctionInputs[$inputArgument], - array($value) - ); - } - } - /* Start Block: "Explode" all the posible test cases defined in the yml - * using domains and single values - */ - //Initialize $index key values for the first test case (5.2 array_fill_keys(array_keys($testFunctionInputs),0)) - $index=array_combine(array_keys($testFunctionInputs),array_fill(0,count($testFunctionInputs),0)); - //array_product() - $prod=1; - foreach($testFunctionInputs as $values) $prod*=count($values); - $lastCase=($prod==0); - while(!$lastCase){ - //foreach($index as $v) echo($v);echo("\n"); - /* Put in $aux one test case */ - $aux=array(); - foreach($testFunctionInputs as $key => $values){ - $aux[$key]=$values[$index[$key]]; - } - /* CREATE TEST CASE: Put $aux test case in $testCases array */ - $i=count($testCases); - $testCases[$i] = $preTestCase; - $testCases[$i]['Input']=$aux; - /* Increse the $index key values to the next test case */ - $lastCase=true; - foreach($testFunctionInputs as $key => $values){ - $index[$key]++; - if ($index[$key]>=count($values)){ - $index[$key]=0; - } - else{ - $lastCase=false; - break; - } - } - } - /*End Block */ - } - /* Start Block: Replace @@ tags variables */ - foreach($testCases as $key => $testCase){ - $testCases[$key]=testTools::replaceVariables( $testCases[$key] ); - $testCases[$key]['Input']=testTools::replaceVariables( $testCases[$key]['Input'], $fields ); - if (isset($testCase['Output'])){ - if (isset($testCase['Output']['Value'])) { - /*$testCases[$key]['Output']['Value'] = - unserialize($testCases[$key]['Output']['Value']);*/ - } - } - } - /* End Block */ - $this->testCases = $testCases; - return $testCases; - } - - /** - * function load - * Increase the number of "planned" tests. - * @access public - * @param int $count - * @param int $start - * @return void - */ - function addToPlan( $count=-1, $start=0 ) - { - foreach($this->testCases as $testCase){ - if (($start==0) && ($count!=0)){ - if (isset($testCase['TODO'])){ - $this->testLime->plan++; - } - else{ - if(isset($testCase['Output'])){ - if ( isset($testCase['Output']['Type']) || - isset($testCase['Output']['Value']) ) - $this->testLime->plan++; - } - } - } - else{ - $start--; - if ($count>0) - $count--; - } - } - } - - /** - * function run - * @access public - * @param object $testerObject - * @param array $fields - * @param int $count - * @param int $start - * @return array - */ - function run( &$testerObject, $fields=array(), $count=-1, $start=0 ) - { - $results=array(); - //$this->addToPlan( $count, $start ); - $functions=get_class_methods( get_class($testerObject) ); - foreach($functions as $id=>$fn) - $functions[$id]=strtolower($fn); - foreach($this->testCases as $index => $testCase){ - if (($start==0) && ($count!=0)){ - if (isset($testCase['TODO'])){ - $this->testLime->todo($testCase['TODO']); - } - else{ - if (isset($testCase['Function'])){ - if (array_search(strtolower($testCase['Function']),$functions)!==FALSE){ - $testCase['Input'] = G::array_merges( $testCase['Input'] , $fields ); - $result = eval('return $testerObject->'.$testCase['Function'].'($testCase, $testCase["Input"]);'); - $results[]=$result; - /* Start Block: Test the $result */ - if (isset($testCase['Output'])){ - if (isset($testCase['Output']['Value'])){ - //$this->testLime->is( $result, $testCase['Output']['Value'], $testCase['Title'] ); - $this->testLime->todo( ($testCase['Output']['Type']) ); - $this->testLime->diag("/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204"); - } - elseif (isset($testCase['Output']['Type'])){ - // $this->testLime->isa_ok( $result, $testCase['Output']['Type'], $testCase['Title'] ); - $this->testLime->todo( ($testCase['Output']['Type']) ); - $this->testLime->diag("/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204"); - } - } - /* End Block */ - } - else{ - $this->testLime->fail( 'Case #'.$index.': Test function (Function) is not present in tester object.' ); - } - } - else{ - $this->testLime->fail( 'Case #'.$index.' doesn\'t have a test function (Function) defined.' ); - } - } - } - else{ - $start--; - if ($count>0) - $count--; - } - } - return $results; - } - - /** - * function runSingle - * @access public - * @param object $testerObject - * @param array $fields - * @return array - */ - function runSingle( &$testerObject, $fields=array() ) - { - $results = $this->run( $testerObject, $fields, 1, 0 ); - return $results[0]; - } + public $testCaseFile; + public $testCases = array (); - /** - * function runMultiple - * @access public - * @param object $testerObject - * @param array $fields - * @param int $count - * @param int $start - * @return array - */ - function runMultiple( &$testerObject, $fields=array(), $count = -1, $start=0) - { - return $this->run( $testerObject, $fields, $count, $start ); - } + /** + * function TestCases + * + * @access public + * @param string $testCaseFile + * @param string $testDomain + * @param string $testLime + * @return void + */ + public function ymlTestCases ($testCaseFile, &$testDomain, &$testLime) + { + $this->testDomain = & $testDomain; + $this->testLime = & $testLime; + if (basename( $testCaseFile ) === $testCaseFile) { + $testCaseFile = PATH_FIXTURES . $testCaseFile; + } + $this->testCaseFile = $testCaseFile; + } + + /** + * function load + * + * @access public + * @param string $inputTestCasesIndex + * @param array $fields + * @return array + */ + public function load ($inputTestCasesIndex = 'TestCases', $fields = array()) + { + $testCases = array (); + $input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile ); + foreach ($input[$inputTestCasesIndex] as $preTestCase) { + $testFunctionInputs = array (); + foreach ($preTestCase['Input'] as $inputArgument => $value) { + if (substr( $inputArgument, - 2, 2 ) === '[]') { + //DOMAIN + $inputArgument = substr( $inputArgument, 0, strlen( $inputArgument ) - 2 ); + if (! isset( $testFunctionInputs[$inputArgument] )) { + $testFunctionInputs[$inputArgument] = array (); + } + //var_dump($this->testDomain->global,$this->testDomain->get( $value ), $value ); + ymlDomain::arrayAppend( $testFunctionInputs[$inputArgument], $this->testDomain->get( $value ) ); + } else { + //SPECIFIC VALUE + if (! isset( $testFunctionInputs[$inputArgument] )) { + $testFunctionInputs[$inputArgument] = array (); + } + ymlDomain::arrayAppend( $testFunctionInputs[$inputArgument], array ($value) ); + } + } + /* Start Block: "Explode" all the posible test cases defined in the yml + * using domains and single values + */ + //Initialize $index key values for the first test case (5.2 array_fill_keys(array_keys($testFunctionInputs),0)) + $index = array_combine( array_keys( $testFunctionInputs ), array_fill( 0, count( $testFunctionInputs ), 0 ) ); + //array_product() + $prod = 1; + foreach ($testFunctionInputs as $values) { + $prod *= count( $values ); + } + $lastCase = ($prod == 0); + while (! $lastCase) { + //foreach($index as $v) echo($v);echo("\n"); + /* Put in $aux one test case */ + $aux = array (); + foreach ($testFunctionInputs as $key => $values) { + $aux[$key] = $values[$index[$key]]; + } + /* CREATE TEST CASE: Put $aux test case in $testCases array */ + $i = count( $testCases ); + $testCases[$i] = $preTestCase; + $testCases[$i]['Input'] = $aux; + /* Increse the $index key values to the next test case */ + $lastCase = true; + foreach ($testFunctionInputs as $key => $values) { + $index[$key] ++; + if ($index[$key] >= count( $values )) { + $index[$key] = 0; + } else { + $lastCase = false; + break; + } + } + } + /*End Block */ + } + /* Start Block: Replace @@ tags variables */ + foreach ($testCases as $key => $testCase) { + $testCases[$key] = testTools::replaceVariables( $testCases[$key] ); + $testCases[$key]['Input'] = testTools::replaceVariables( $testCases[$key]['Input'], $fields ); + if (isset( $testCase['Output'] )) { + if (isset( $testCase['Output']['Value'] )) { + /*$testCases[$key]['Output']['Value'] = + unserialize($testCases[$key]['Output']['Value']);*/ + } + } + } + /* End Block */ + $this->testCases = $testCases; + return $testCases; + } + + /** + * function load + * Increase the number of "planned" tests. + * + * @access public + * @param int $count + * @param int $start + * @return void + */ + public function addToPlan ($count = -1, $start = 0) + { + foreach ($this->testCases as $testCase) { + if (($start == 0) && ($count != 0)) { + if (isset( $testCase['TODO'] )) { + $this->testLime->plan ++; + } else { + if (isset( $testCase['Output'] )) { + if (isset( $testCase['Output']['Type'] ) || isset( $testCase['Output']['Value'] )) { + $this->testLime->plan ++; + } + } + } + } else { + $start --; + if ($count > 0) { + $count --; + } + } + } + } + + /** + * function run + * + * @access public + * @param object $testerObject + * @param array $fields + * @param int $count + * @param int $start + * @return array + */ + public function run (&$testerObject, $fields = array(), $count = -1, $start = 0) + { + $results = array (); + //$this->addToPlan( $count, $start ); + $functions = get_class_methods( get_class( $testerObject ) ); + foreach ($functions as $id => $fn) { + $functions[$id] = strtolower( $fn ); + } + foreach ($this->testCases as $index => $testCase) { + if (($start == 0) && ($count != 0)) { + if (isset( $testCase['TODO'] )) { + $this->testLime->todo( $testCase['TODO'] ); + } else { + if (isset( $testCase['Function'] )) { + if (array_search( strtolower( $testCase['Function'] ), $functions ) !== false) { + $testCase['Input'] = G::array_merges( $testCase['Input'], $fields ); + $result = eval( 'return $testerObject->' . $testCase['Function'] . '($testCase, $testCase["Input"]);' ); + $results[] = $result; + /* Start Block: Test the $result */ + if (isset( $testCase['Output'] )) { + if (isset( $testCase['Output']['Value'] )) { + //$this->testLime->is( $result, $testCase['Output']['Value'], $testCase['Title'] ); + $this->testLime->todo( ($testCase['Output']['Type']) ); + $this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" ); + } elseif (isset( $testCase['Output']['Type'] )) { + // $this->testLime->isa_ok( $result, $testCase['Output']['Type'], $testCase['Title'] ); + $this->testLime->todo( ($testCase['Output']['Type']) ); + $this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" ); + } + } + /* End Block */ + } else { + $this->testLime->fail( 'Case #' . $index . ': Test function (Function) is not present in tester object.' ); + } + } else { + $this->testLime->fail( 'Case #' . $index . ' doesn\'t have a test function (Function) defined.' ); + } + } + } else { + $start --; + if ($count > 0) { + $count --; + } + } + } + return $results; + } + + /** + * function runSingle + * + * @access public + * @param object $testerObject + * @param array $fields + * @return array + */ + public function runSingle (&$testerObject, $fields = array()) + { + $results = $this->run( $testerObject, $fields, 1, 0 ); + return $results[0]; + } + + /** + * function runMultiple + * + * @access public + * @param object $testerObject + * @param array $fields + * @param int $count + * @param int $start + * @return array + */ + public function runMultiple (&$testerObject, $fields = array(), $count = -1, $start = 0) + { + return $this->run( $testerObject, $fields, $count, $start ); + } } +