diff --git a/workflow/engine/classes/model/ReportTable.php b/workflow/engine/classes/model/ReportTable.php index 98bdda7f5..2f44f7b53 100755 --- a/workflow/engine/classes/model/ReportTable.php +++ b/workflow/engine/classes/model/ReportTable.php @@ -1,231 +1,227 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -require_once 'classes/model/Content.php'; -require_once 'classes/model/om/BaseReportTable.php'; - - -/** - * Skeleton subclass for representing a row from the 'REPORT_TABLE' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the output directory. - * - * @package workflow.engine.classes.model - */ -class ReportTable extends BaseReportTable { - /** - * This value goes in the content table - * @var string - */ - protected $rep_tab_title = ''; - - /** - * Get the rep_tab_title column value. - * @return string - */ - public function getRepTabTitle() { - if ( $this->getRepTabUid() == "" ) { - throw ( new Exception( "Error in getRepTabTitle, the getRepTabUid() can't be blank") ); - } - $lang = defined ( 'SYS_LANG' ) ? SYS_LANG : 'en'; - $this->rep_tab_title = Content::load ( 'REP_TAB_TITLE', '', $this->getRepTabUid(), $lang ); - return $this->rep_tab_title; - } - - /** - * Set the rep_tab_title column value. - * - * @param string $v new value - * @return void - */ - public function setRepTabTitle($v) - { - if ( $this->getRepTabUid() == "" ) { - throw ( new Exception( "Error in setRepTabTitle, the setRepTabUid() can't be blank") ); - } - $v=isset($v)?((string)$v):''; - $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en'; - if ($this->rep_tab_title !== $v || $v==="") { - $this->rep_tab_title = $v; - $res = Content::addContent( 'REP_TAB_TITLE', '', $this->getRepTabUid(), $lang, $this->rep_tab_title ); - return $res; - } - return 0; - } - - public function load($RepTabUid) - { - try { - $oRow = ReportTablePeer::retrieveByPK( $RepTabUid ); - if (!is_null($oRow)) - { - $aFields = $oRow->toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - $this->setNew(false); - $this->setRepTabTitle($aFields['REP_TAB_TITLE']=$this->getRepTabTitle()); - return $aFields; - } - else { - //throw( new Exception( "The row '$RepTabUid' in table ReportTable doesn't exist!" )); - return array(); - } - } - catch (Exception $oError) { - throw($oError); - } - } - public function create($aData) - { - $con = Propel::getConnection(ReportTablePeer::DATABASE_NAME); - try - { - $con->begin(); - if ( isset ( $aData['REP_TAB_UID'] ) && $aData['REP_TAB_UID']== '' ) - unset ( $aData['REP_TAB_UID'] ); - if ( !isset ( $aData['REP_TAB_UID'] ) ) - $this->setRepTabUid(G::generateUniqueID()); - else - $this->setRepTabUid($aData['REP_TAB_UID'] ); - - $this->setProUid($aData['PRO_UID']); - $this->setRepTabName($aData['REP_TAB_NAME']); - $this->setRepTabType($aData['REP_TAB_TYPE']); - if ( !isset ( $aData['REP_TAB_GRID'] ) ) - $this->setRepTabGrid(""); - else - $this->setRepTabGrid( $aData['REP_TAB_GRID'] ); - if ( !isset ( $aData['REP_TAB_CONNECTION'] ) ) - $this->setRepTabConnection("report"); - else - $this->setRepTabConnection( $aData['REP_TAB_CONNECTION'] ); - $this->setRepTabCreateDate(date('Y-m-d H:i:s')); - $this->setRepTabStatus('ACTIVE'); - - if($this->validate()) - { - if ( !isset ( $aData['REP_TAB_TITLE'] ) ) - $this->setRepTabTitle(""); - else - $this->setRepTabTitle( $aData['REP_TAB_TITLE'] ); - - $result=$this->save(); - $con->commit(); - return $result; - } - else - { - $con->rollback(); - throw(new Exception("Failed Validation in class ".get_class($this).".")); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - public function update($fields) - { - $con = Propel::getConnection(ReportTablePeer::DATABASE_NAME); - try - { - $con->begin(); - $this->load($fields['REP_TAB_UID']); - $this->fromArray($fields,BasePeer::TYPE_FIELDNAME); - - $sDataBase = 'database_' . strtolower(DB_ADAPTER); - if(G::LoadSystemExist($sDataBase)){ - G::LoadSystem($sDataBase); - $oDataBase = new database(); - $oValidate = $oDataBase->getValidate($this->validate()); - } else { - $oValidate = $this->validate(); - } - // if($this->validate()) - if($oValidate) - { - $contentResult=0; - if (array_key_exists("REP_TAB_TITLE", $fields)) $contentResult+=$this->setRepTabTitle($fields["REP_TAB_TITLE"]); - $result=$this->save(); - $result=($result==0)?($contentResult>0?1:0):$result; - $con->commit(); - return $result; - } - else - { - $con->rollback(); - $validationE=new Exception("Failed Validation in class ".get_class($this)."."); - $validationE->aValidationFailures = $this->getValidationFailures(); - throw($validationE); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - public function remove($RepTabUid) - { - $con = Propel::getConnection(ReportTablePeer::DATABASE_NAME); - try - { - $con->begin(); - $oRepTab = ReportTablePeer::retrieveByPK( $RepTabUid ); - if (!is_null($oRepTab)) { - Content::removeContent( 'REP_TAB_TITLE', '', $this->getRepTabUid()); - $result = $oRepTab->delete(); - $con->commit(); - } - return $result; - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - - function reportTableExists ( $RepTabUid ) { - $con = Propel::getConnection(ReportTablePeer::DATABASE_NAME); - try { - $oRepTabUid = ReportTablePeer::retrieveByPk( $RepTabUid ); - if (is_object($oRepTabUid) && get_class ($oRepTabUid) == 'ReportTable' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } -} // ReportTable +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +require_once 'classes/model/Content.php'; +require_once 'classes/model/om/BaseReportTable.php'; + +/** + * Skeleton subclass for representing a row from the 'REPORT_TABLE' table. + * + * + * + * You should add additional methods to this class to meet the + * application requirements. This class will only be generated as + * long as it does not already exist in the output directory. + * + * @package workflow.engine.classes.model + */ +class ReportTable extends BaseReportTable +{ + /** + * This value goes in the content table + * + * @var string + */ + protected $rep_tab_title = ''; + + /** + * Get the rep_tab_title column value. + * + * @return string + */ + public function getRepTabTitle () + { + if ($this->getRepTabUid() == "") { + throw (new Exception( "Error in getRepTabTitle, the getRepTabUid() can't be blank" )); + } + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $this->rep_tab_title = Content::load( 'REP_TAB_TITLE', '', $this->getRepTabUid(), $lang ); + return $this->rep_tab_title; + } + + /** + * Set the rep_tab_title column value. + * + * @param string $v new value + * @return void + */ + public function setRepTabTitle ($v) + { + if ($this->getRepTabUid() == "") { + throw (new Exception( "Error in setRepTabTitle, the setRepTabUid() can't be blank" )); + } + $v = isset( $v ) ? ((string) $v) : ''; + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + if ($this->rep_tab_title !== $v || $v === "") { + $this->rep_tab_title = $v; + $res = Content::addContent( 'REP_TAB_TITLE', '', $this->getRepTabUid(), $lang, $this->rep_tab_title ); + return $res; + } + return 0; + } + + public function load ($RepTabUid) + { + try { + $oRow = ReportTablePeer::retrieveByPK( $RepTabUid ); + if (! is_null( $oRow )) { + $aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $this->setNew( false ); + $this->setRepTabTitle( $aFields['REP_TAB_TITLE'] = $this->getRepTabTitle() ); + return $aFields; + } else { + //throw( new Exception( "The row '$RepTabUid' in table ReportTable doesn't exist!" )); + return array (); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function create ($aData) + { + $con = Propel::getConnection( ReportTablePeer::DATABASE_NAME ); + try { + $con->begin(); + if (isset( $aData['REP_TAB_UID'] ) && $aData['REP_TAB_UID'] == '') { + unset( $aData['REP_TAB_UID'] ); + } + if (! isset( $aData['REP_TAB_UID'] )) { + $this->setRepTabUid( G::generateUniqueID() ); + } else { + $this->setRepTabUid( $aData['REP_TAB_UID'] ); + } + + $this->setProUid( $aData['PRO_UID'] ); + $this->setRepTabName( $aData['REP_TAB_NAME'] ); + $this->setRepTabType( $aData['REP_TAB_TYPE'] ); + if (! isset( $aData['REP_TAB_GRID'] )) { + $this->setRepTabGrid( "" ); + } else { + $this->setRepTabGrid( $aData['REP_TAB_GRID'] ); + } + if (! isset( $aData['REP_TAB_CONNECTION'] )) { + $this->setRepTabConnection( "report" ); + } else { + $this->setRepTabConnection( $aData['REP_TAB_CONNECTION'] ); + } + $this->setRepTabCreateDate( date( 'Y-m-d H:i:s' ) ); + $this->setRepTabStatus( 'ACTIVE' ); + + if ($this->validate()) { + if (! isset( $aData['REP_TAB_TITLE'] )) { + $this->setRepTabTitle( "" ); + } else { + $this->setRepTabTitle( $aData['REP_TAB_TITLE'] ); + } + $result = $this->save(); + $con->commit(); + return $result; + } else { + $con->rollback(); + throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." )); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function update ($fields) + { + $con = Propel::getConnection( ReportTablePeer::DATABASE_NAME ); + try { + $con->begin(); + $this->load( $fields['REP_TAB_UID'] ); + $this->fromArray( $fields, BasePeer::TYPE_FIELDNAME ); + + $sDataBase = 'database_' . strtolower( DB_ADAPTER ); + if (G::LoadSystemExist( $sDataBase )) { + G::LoadSystem( $sDataBase ); + $oDataBase = new database(); + $oValidate = $oDataBase->getValidate( $this->validate() ); + } else { + $oValidate = $this->validate(); + } + // if($this->validate()) + if ($oValidate) { + $contentResult = 0; + if (array_key_exists( "REP_TAB_TITLE", $fields )) { + $contentResult += $this->setRepTabTitle( $fields["REP_TAB_TITLE"] ); + } + $result = $this->save(); + $result = ($result == 0) ? ($contentResult > 0 ? 1 : 0) : $result; + $con->commit(); + return $result; + } else { + $con->rollback(); + $validationE = new Exception( "Failed Validation in class " . get_class( $this ) . "." ); + $validationE->aValidationFailures = $this->getValidationFailures(); + throw ($validationE); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function remove ($RepTabUid) + { + $con = Propel::getConnection( ReportTablePeer::DATABASE_NAME ); + try { + $con->begin(); + $oRepTab = ReportTablePeer::retrieveByPK( $RepTabUid ); + if (! is_null( $oRepTab )) { + Content::removeContent( 'REP_TAB_TITLE', '', $this->getRepTabUid() ); + $result = $oRepTab->delete(); + $con->commit(); + } + return $result; + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function reportTableExists ($RepTabUid) + { + $con = Propel::getConnection( ReportTablePeer::DATABASE_NAME ); + try { + $oRepTabUid = ReportTablePeer::retrieveByPk( $RepTabUid ); + if (is_object( $oRepTabUid ) && get_class( $oRepTabUid ) == 'ReportTable') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } +} +// ReportTable + diff --git a/workflow/engine/classes/model/Route.php b/workflow/engine/classes/model/Route.php index c73134b21..2e94c8dcf 100755 --- a/workflow/engine/classes/model/Route.php +++ b/workflow/engine/classes/model/Route.php @@ -1,216 +1,217 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -require_once 'classes/model/om/BaseRoute.php'; -require_once 'classes/model/Content.php'; - -/** - * Skeleton subclass for representing a row from the 'ROUTE' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the output directory. - * - * @package workflow.engine.classes.model - */ -class Route extends BaseRoute { - - /* +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +require_once 'classes/model/om/BaseRoute.php'; +require_once 'classes/model/Content.php'; + +/** + * Skeleton subclass for representing a row from the 'ROUTE' table. + * + * + * + * You should add additional methods to this class to meet the + * application requirements. This class will only be generated as + * long as it does not already exist in the output directory. + * + * @package workflow.engine.classes.model + */ +class Route extends BaseRoute +{ + + /* * Load the application document registry * @param string $sRouUid * @return variant - */ - public function load($sRouUid) - { - try { - $oRoute = RoutePeer::retrieveByPK($sRouUid); - if (!is_null($oRoute)) - { - $aFields = $oRoute->toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - return $aFields; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Create the application document registry - * @param array $aData - * @return string - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(RoutePeer::DATABASE_NAME); - try { - $sRouteUID = G::generateUniqueID(); - $aData['ROU_UID'] = $sRouteUID; - $oRoute = new Route(); - - // validating default values - $aData['ROU_TO_LAST_USER'] = $this->validateValue(isset($aData['ROU_TO_LAST_USER']) ? $aData['ROU_TO_LAST_USER'] : '', array('TRUE', 'FALSE'), 'FALSE'); - $aData['ROU_OPTIONAL'] = $this->validateValue(isset($aData['ROU_OPTIONAL']) ? $aData['ROU_OPTIONAL'] : '', array('TRUE', 'FALSE'), 'FALSE'); - $aData['ROU_SEND_EMAIL'] = $this->validateValue(isset($aData['ROU_SEND_EMAIL']) ? $aData['ROU_SEND_EMAIL']: '', array('TRUE', 'FALSE'), 'TRUE'); - - $oRoute->fromArray($aData, BasePeer::TYPE_FIELDNAME); - - if ($oRoute->validate()) { - $oConnection->begin(); - $iResult = $oRoute->save(); - $oConnection->commit(); - return $sRouteUID; - } - else { - $sMessage = ''; - $aValidationFailures = $oRoute->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Update the application document registry - * @param array $aData - * @return string - **/ - public function update($aData) - { - $oConnection = Propel::getConnection(RoutePeer::DATABASE_NAME); - try { - $oRoute = RoutePeer::retrieveByPK($aData['ROU_UID']); - if (!is_null($oRoute)) - { - // validating default values - if (isset($aData['ROU_TO_LAST_USER'])) { - $aData['ROU_TO_LAST_USER'] = $this->validateValue($aData['ROU_TO_LAST_USER'], array('TRUE', 'FALSE'), 'FALSE'); - } - if (isset($aData['ROU_OPTIONAL'])) { - $aData['ROU_OPTIONAL'] = $this->validateValue($aData['ROU_OPTIONAL'], array('TRUE', 'FALSE'), 'FALSE'); - } - if (isset($aData['ROU_SEND_EMAIL'])) { - $aData['ROU_SEND_EMAIL'] = $this->validateValue($aData['ROU_SEND_EMAIL'], array('TRUE', 'FALSE'), 'TRUE'); - } - - $oRoute->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oRoute->validate()) { - $oConnection->begin(); - $iResult = $oRoute->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oRoute->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The ROUTE tables cannot be updated!
'.$sMessage)); - } - } - else { - throw(new Exception( "The row " . $aData['ROU_UID'] . " doesn't exist!" )); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the application document registry - * @param array $aData - * @return string - **/ - public function remove($sRouUid) - { - $oConnection = Propel::getConnection(RoutePeer::DATABASE_NAME); - try { - $oRoute = RoutePeer::retrieveByPK($sRouUid); - if (!is_null($oRoute)) - { - $oConnection->begin(); - $iResult = $oRoute->delete(); - $oConnection->commit(); - return $iResult; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - function routeExists ( $sRouUid ) { - $con = Propel::getConnection(RoutePeer::DATABASE_NAME); - try { - $oRouUid = RoutePeer::retrieveByPk( $sRouUid ); - if (is_object($oRouUid) && get_class ($oRouUid) == 'Route' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Validate value for a variable that only accepts some determinated values - * - * @param $value string - value to test - * @param $validValues array - list of valid values - * @param $default string default value, if the tested value is not valid the default value is returned - * @return the tested and accepted value - */ - function validateValue($value, $validValues, $default) - { - if (!in_array($value, $validValues)) { - $value = $default; - } - - return $value; - } -} // Route + */ + public function load ($sRouUid) + { + try { + $oRoute = RoutePeer::retrieveByPK( $sRouUid ); + if (! is_null( $oRoute )) { + $aFields = $oRoute->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + return $aFields; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create the application document registry + * + * @param array $aData + * @return string + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( RoutePeer::DATABASE_NAME ); + try { + $sRouteUID = G::generateUniqueID(); + $aData['ROU_UID'] = $sRouteUID; + $oRoute = new Route(); + + // validating default values + $aData['ROU_TO_LAST_USER'] = $this->validateValue( isset( $aData['ROU_TO_LAST_USER'] ) ? $aData['ROU_TO_LAST_USER'] : '', array ('TRUE','FALSE' + ), 'FALSE' ); + $aData['ROU_OPTIONAL'] = $this->validateValue( isset( $aData['ROU_OPTIONAL'] ) ? $aData['ROU_OPTIONAL'] : '', array ('TRUE','FALSE' + ), 'FALSE' ); + $aData['ROU_SEND_EMAIL'] = $this->validateValue( isset( $aData['ROU_SEND_EMAIL'] ) ? $aData['ROU_SEND_EMAIL'] : '', array ('TRUE','FALSE' + ), 'TRUE' ); + + $oRoute->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + + if ($oRoute->validate()) { + $oConnection->begin(); + $iResult = $oRoute->save(); + $oConnection->commit(); + return $sRouteUID; + } else { + $sMessage = ''; + $aValidationFailures = $oRoute->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + /** + * Update the application document registry + * + * @param array $aData + * @return string + * + */ + public function update ($aData) + { + $oConnection = Propel::getConnection( RoutePeer::DATABASE_NAME ); + try { + $oRoute = RoutePeer::retrieveByPK( $aData['ROU_UID'] ); + if (! is_null( $oRoute )) { + // validating default values + if (isset( $aData['ROU_TO_LAST_USER'] )) { + $aData['ROU_TO_LAST_USER'] = $this->validateValue( $aData['ROU_TO_LAST_USER'], array ('TRUE','FALSE' + ), 'FALSE' ); + } + if (isset( $aData['ROU_OPTIONAL'] )) { + $aData['ROU_OPTIONAL'] = $this->validateValue( $aData['ROU_OPTIONAL'], array ('TRUE','FALSE' + ), 'FALSE' ); + } + if (isset( $aData['ROU_SEND_EMAIL'] )) { + $aData['ROU_SEND_EMAIL'] = $this->validateValue( $aData['ROU_SEND_EMAIL'], array ('TRUE','FALSE' + ), 'TRUE' ); + } + + $oRoute->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oRoute->validate()) { + $oConnection->begin(); + $iResult = $oRoute->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oRoute->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The ROUTE tables cannot be updated!
' . $sMessage )); + } + } else { + throw (new Exception( "The row " . $aData['ROU_UID'] . " doesn't exist!" )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the application document registry + * + * @param array $aData + * @return string + * + */ + public function remove ($sRouUid) + { + $oConnection = Propel::getConnection( RoutePeer::DATABASE_NAME ); + try { + $oRoute = RoutePeer::retrieveByPK( $sRouUid ); + if (! is_null( $oRoute )) { + $oConnection->begin(); + $iResult = $oRoute->delete(); + $oConnection->commit(); + return $iResult; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function routeExists ($sRouUid) + { + $con = Propel::getConnection( RoutePeer::DATABASE_NAME ); + try { + $oRouUid = RoutePeer::retrieveByPk( $sRouUid ); + if (is_object( $oRouUid ) && get_class( $oRouUid ) == 'Route') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Validate value for a variable that only accepts some determinated values + * + * @param $value string - value to test + * @param $validValues array - list of valid values + * @param $default string default value, if the tested value is not valid the default value is returned + * @return the tested and accepted value + */ + public function validateValue ($value, $validValues, $default) + { + if (! in_array( $value, $validValues )) { + $value = $default; + } + return $value; + } +} +// Route + diff --git a/workflow/engine/classes/model/Stage.php b/workflow/engine/classes/model/Stage.php index f9dddfa2e..f43c1a34e 100755 --- a/workflow/engine/classes/model/Stage.php +++ b/workflow/engine/classes/model/Stage.php @@ -1,200 +1,193 @@ -getStgUid() == "" ) { - throw ( new Exception( "Error in getStgTitle, the getStgUid() can't be blank") ); - } - $lang = defined ( 'SYS_LANG' ) ? SYS_LANG : 'en'; - $this->stg_title = Content::load ( 'STG_TITLE', '', $this->getStgUid(), $lang ); - return $this->stg_title; - } - - /** - * Set the stg_title column value. - * - * @param string $v new value - * @return void - */ - public function setStgTitle($v) - { - if ( $this->getStgUid() == "" ) { - throw ( new Exception( "Error in setStgTitle, the setStgUid() can't be blank") ); - } - $v=isset($v)?((string)$v):''; - $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en'; - if ($this->stg_title !== $v || $v==="") { - $this->stg_title = $v; - $res = Content::addContent( 'STG_TITLE', '', $this->getStgUid(), $lang, $this->stg_title ); - return $res; - } - return 0; - } - - public function load($StgUid) - { - try { - $oRow = StagePeer::retrieveByPK( $StgUid ); - if (!is_null($oRow)) - { - $aFields = $oRow->toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - $this->setNew(false); - $this->setStgTitle($aFields['STG_TITLE'] = $this->getStgTitle()); - return $aFields; - } - else { - throw( new Exception( "The row '$StgUid' in table Stage doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - public function create($aData) { - $oConnection = Propel::getConnection(StagePeer::DATABASE_NAME); - try { - if ( isset ( $aData['STG_UID'] ) && $aData['STG_UID']== '' ) - unset ( $aData['STG_UID'] ); - if ( !isset ( $aData['STG_UID'] ) ) - $aData['STG_UID'] = G::generateUniqueID(); - $oStage = new Stage(); - $oStage->fromArray($aData, BasePeer::TYPE_FIELDNAME); - $oStage->setStgTitle($aData['STG_TITLE']); - if ($oStage->validate()) { - $oConnection->begin(); - $iResult = $oStage->save(); - $oConnection->commit(); - return $aData['STG_UID']; - } - else { - $sMessage = ''; - $aValidationFailures = $oStage->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - public function update($fields) - { - $con = Propel::getConnection(StagePeer::DATABASE_NAME); - try - { - $con->begin(); - $this->load($fields['STG_UID']); - $this->fromArray($fields, BasePeer::TYPE_FIELDNAME); - if($this->validate()) - { - $contentResult=0; - if (array_key_exists("STG_TITLE", $fields)) $contentResult+=$this->setStgTitle($fields["STG_TITLE"]); - $result=$this->save(); - $result=($result==0)?($contentResult>0?1:0):$result; - $con->commit(); - return $result; - } - else - { - $con->rollback(); - $validationE=new Exception("Failed Validation in class ".get_class($this)."."); - $validationE->aValidationFailures = $this->getValidationFailures(); - throw($validationE); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - - public function remove($StgUid) - { - $con = Propel::getConnection(StagePeer::DATABASE_NAME); - try - { - $con->begin(); - $oStage = StagePeer::retrieveByPK( $StgUid ); - if (!is_null($oStage)) { - Content::removeContent( 'STG_TITLE', '', $this->getStgUid()); - $result = $oStage->delete(); - $con->commit(); - } - return $result; - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - - function reorderPositions($sProcessUID, $iIndex) { - try { - $oCriteria = new Criteria('workflow'); - $oCriteria->add(StagePeer::PRO_UID, $sProcessUID); - $oCriteria->add(StagePeer::STG_INDEX, $iIndex, '>'); - $oDataset = StagePeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $this->update(array('STG_UID' => $aRow['STG_UID'], - 'PRO_UID' => $aRow['PRO_UID'], - 'STG_POSX' => $aRow['STG_POSX'], - 'STG_POSY' => $aRow['STG_POSY'], - 'STG_INDEX' => $aRow['STG_INDEX'] - 1)); - $oDataset->next(); - } - } - catch (Exception $oException) { - throw $Exception; - } - } - - function Exists ( $sUid ) { - try { - $oObj = StagePeer::retrieveByPk($sUid); - return (is_object($oObj) && get_class($oObj) == 'Stage'); - } - catch (Exception $oError) { - throw($oError); - } - } -} // Stage +getStgUid() == "") { + throw (new Exception( "Error in getStgTitle, the getStgUid() can't be blank" )); + } + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $this->stg_title = Content::load( 'STG_TITLE', '', $this->getStgUid(), $lang ); + return $this->stg_title; + } + + /** + * Set the stg_title column value. + * + * @param string $v new value + * @return void + */ + public function setStgTitle ($v) + { + if ($this->getStgUid() == "") { + throw (new Exception( "Error in setStgTitle, the setStgUid() can't be blank" )); + } + $v = isset( $v ) ? ((string) $v) : ''; + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + if ($this->stg_title !== $v || $v === "") { + $this->stg_title = $v; + $res = Content::addContent( 'STG_TITLE', '', $this->getStgUid(), $lang, $this->stg_title ); + return $res; + } + return 0; + } + + public function load ($StgUid) + { + try { + $oRow = StagePeer::retrieveByPK( $StgUid ); + if (! is_null( $oRow )) { + $aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $this->setNew( false ); + $this->setStgTitle( $aFields['STG_TITLE'] = $this->getStgTitle() ); + return $aFields; + } else { + throw (new Exception( "The row '$StgUid' in table Stage doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function create ($aData) + { + $oConnection = Propel::getConnection( StagePeer::DATABASE_NAME ); + try { + if (isset( $aData['STG_UID'] ) && $aData['STG_UID'] == '') { + unset( $aData['STG_UID'] ); + } + if (! isset( $aData['STG_UID'] )) { + $aData['STG_UID'] = G::generateUniqueID(); + } + $oStage = new Stage(); + $oStage->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + $oStage->setStgTitle( $aData['STG_TITLE'] ); + if ($oStage->validate()) { + $oConnection->begin(); + $iResult = $oStage->save(); + $oConnection->commit(); + return $aData['STG_UID']; + } else { + $sMessage = ''; + $aValidationFailures = $oStage->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function update ($fields) + { + $con = Propel::getConnection( StagePeer::DATABASE_NAME ); + try { + $con->begin(); + $this->load( $fields['STG_UID'] ); + $this->fromArray( $fields, BasePeer::TYPE_FIELDNAME ); + if ($this->validate()) { + $contentResult = 0; + if (array_key_exists( "STG_TITLE", $fields )) { + $contentResult += $this->setStgTitle( $fields["STG_TITLE"] ); + } + $result = $this->save(); + $result = ($result == 0) ? ($contentResult > 0 ? 1 : 0) : $result; + $con->commit(); + return $result; + } else { + $con->rollback(); + $validationE = new Exception( "Failed Validation in class " . get_class( $this ) . "." ); + $validationE->aValidationFailures = $this->getValidationFailures(); + throw ($validationE); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function remove ($StgUid) + { + $con = Propel::getConnection( StagePeer::DATABASE_NAME ); + try { + $con->begin(); + $oStage = StagePeer::retrieveByPK( $StgUid ); + if (! is_null( $oStage )) { + Content::removeContent( 'STG_TITLE', '', $this->getStgUid() ); + $result = $oStage->delete(); + $con->commit(); + } + return $result; + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function reorderPositions ($sProcessUID, $iIndex) + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StagePeer::PRO_UID, $sProcessUID ); + $oCriteria->add( StagePeer::STG_INDEX, $iIndex, '>' ); + $oDataset = StagePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $this->update( array ('STG_UID' => $aRow['STG_UID'],'PRO_UID' => $aRow['PRO_UID'],'STG_POSX' => $aRow['STG_POSX'],'STG_POSY' => $aRow['STG_POSY'],'STG_INDEX' => $aRow['STG_INDEX'] - 1 + ) ); + $oDataset->next(); + } + } catch (Exception $oException) { + throw $Exception; + } + } + + public function Exists ($sUid) + { + try { + $oObj = StagePeer::retrieveByPk( $sUid ); + return (is_object( $oObj ) && get_class( $oObj ) == 'Stage'); + } catch (Exception $oError) { + throw ($oError); + } + } +} +// Stage + diff --git a/workflow/engine/classes/model/StepSupervisor.php b/workflow/engine/classes/model/StepSupervisor.php index a69e165c6..2c741740b 100755 --- a/workflow/engine/classes/model/StepSupervisor.php +++ b/workflow/engine/classes/model/StepSupervisor.php @@ -1,230 +1,229 @@ -toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields,BasePeer::TYPE_FIELDNAME); - $this->setNew(false); - return $aFields; - } - else { - throw( new Exception( "The row '$Uid' in table StepSupervisor doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - function Exists ( $Uid ) { - try { - $oPro = StepSupervisorPeer::retrieveByPk( $Uid ); - if (is_object($oPro) && get_class ($oPro) == 'StepSupervisor' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Create the step supervisor registry - * @param array $aData - * @return boolean - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(StepSupervisorPeer::DATABASE_NAME); - try { - if ( isset ( $aData['STEP_UID'] ) && $aData['STEP_UID']== '' ) - unset ( $aData['STEP_UID'] ); - if ( !isset ( $aData['STEP_UID'] ) ) - $aData['STEP_UID'] = G::generateUniqueID(); - $oStepSupervisor = new StepSupervisor(); - $oStepSupervisor->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oStepSupervisor->validate()) { - $oConnection->begin(); - $iResult = $oStepSupervisor->save(); - $oConnection->commit(); - return true; - } - else { - $sMessage = ''; - $aValidationFailures = $oStepSupervisor->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Update the step supervisor registry - * @param array $aData - * @return integer - **/ - public function update($aData) - { - $oConnection = Propel::getConnection(StepSupervisorPeer::DATABASE_NAME); - try { - $oStepSupervisor = StepSupervisorPeer::retrieveByPK($aData['STEP_UID']); - if (!is_null($oStepSupervisor)) - { - $oStepSupervisor->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oStepSupervisor->validate()) { - $oConnection->begin(); - $iResult = $oStepSupervisor->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oStepSupervisor->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be updated!
'.$sMessage)); - } - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the step supervisor registry - * @param string $sStepUID - * @return integer - **/ - public function remove($sStepUID) - { - $oConnection = Propel::getConnection(StepSupervisorPeer::DATABASE_NAME); - try { - $oConnection->begin(); - $this->setStepUid($sStepUID); - $iResult = $this->delete(); - $oConnection->commit(); - return $iResult; - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Get the next position for a atep - * @param string $sProcessUID - * @return integer - **/ - function getNextPosition($sProcessUID, $sType) { - try { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn('(COUNT(*) + 1) AS POSITION'); - $oCriteria->add(StepSupervisorPeer::PRO_UID, $sProcessUID); - $oCriteria->add(StepSupervisorPeer::STEP_TYPE_OBJ, $sType); - $oDataset = StepSupervisorPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aRow = $oDataset->getRow(); - return (int)$aRow['POSITION']; - } - catch (Exception $oException) { - throw $Exception; - } - } - - /** - * Reorder the steps positions - * @param string $sProcessUID - * @param string $iPosition - **/ - function reorderPositions($sProcessUID, $iPosition, $sType) { - try { - $oCriteria = new Criteria('workflow'); - $oCriteria->add(StepSupervisorPeer::PRO_UID, $sProcessUID); - $oCriteria->add(StepSupervisorPeer::STEP_TYPE_OBJ, $sType); - $oCriteria->add(StepSupervisorPeer::STEP_POSITION, $iPosition, '>'); - $oDataset = StepSupervisorPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next();var_dump(StepSupervisorPeer::doCount($oCriteria)); - while ($aRow = $oDataset->getRow()) {var_dump($aRow);echo "\n"; - $this->update(array('STEP_UID' => $aRow['STEP_UID'], - 'PRO_UID' => $aRow['PRO_UID'], - 'STEP_TYPE_OBJ' => $aRow['STEP_TYPE_OBJ'], - 'STEP_UID_OBJ' => $aRow['STEP_UID_OBJ'], - 'STEP_POSITION' => $aRow['STEP_POSITION'] - 1)); - $oDataset->next(); - } - } - catch (Exception $oException) { - throw $Exception; - } - } - - - function removeByObject($sType, $sObjUid) { - try { - $oCriteria = new Criteria('workflow'); - $oCriteria->add(StepSupervisorPeer::STEP_TYPE_OBJ, $sType); - $oCriteria->add(StepSupervisorPeer::STEP_UID_OBJ, $sObjUid); - StepSupervisorPeer::doDelete($oCriteria); - } - catch(Exception $e) { - throw($e); - } - } - -function loadInfo($sObjUID){ - - $oCriteria = new Criteria('workflow'); - $oCriteria->add(StepSupervisorPeer::STEP_UID_OBJ, $sObjUID); - $oDataset = StepSupervisorPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aRow = $oDataset->getRow(); - return($aRow); - - - } - - -} // StepSupervisor +toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $this->setNew( false ); + return $aFields; + } else { + throw (new Exception( "The row '$Uid' in table StepSupervisor doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function Exists ($Uid) + { + try { + $oPro = StepSupervisorPeer::retrieveByPk( $Uid ); + if (is_object( $oPro ) && get_class( $oPro ) == 'StepSupervisor') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create the step supervisor registry + * + * @param array $aData + * @return boolean + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( StepSupervisorPeer::DATABASE_NAME ); + try { + if (isset( $aData['STEP_UID'] ) && $aData['STEP_UID'] == '') { + unset( $aData['STEP_UID'] ); + } + if (! isset( $aData['STEP_UID'] )) { + $aData['STEP_UID'] = G::generateUniqueID(); + } + $oStepSupervisor = new StepSupervisor(); + $oStepSupervisor->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oStepSupervisor->validate()) { + $oConnection->begin(); + $iResult = $oStepSupervisor->save(); + $oConnection->commit(); + return true; + } else { + $sMessage = ''; + $aValidationFailures = $oStepSupervisor->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Update the step supervisor registry + * + * @param array $aData + * @return integer + * + */ + public function update ($aData) + { + $oConnection = Propel::getConnection( StepSupervisorPeer::DATABASE_NAME ); + try { + $oStepSupervisor = StepSupervisorPeer::retrieveByPK( $aData['STEP_UID'] ); + if (! is_null( $oStepSupervisor )) { + $oStepSupervisor->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oStepSupervisor->validate()) { + $oConnection->begin(); + $iResult = $oStepSupervisor->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oStepSupervisor->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be updated!
' . $sMessage )); + } + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the step supervisor registry + * + * @param string $sStepUID + * @return integer + * + */ + public function remove ($sStepUID) + { + $oConnection = Propel::getConnection( StepSupervisorPeer::DATABASE_NAME ); + try { + $oConnection->begin(); + $this->setStepUid( $sStepUID ); + $iResult = $this->delete(); + $oConnection->commit(); + return $iResult; + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Get the next position for a atep + * + * @param string $sProcessUID + * @return integer + * + */ + public function getNextPosition ($sProcessUID, $sType) + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( '(COUNT(*) + 1) AS POSITION' ); + $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProcessUID ); + $oCriteria->add( StepSupervisorPeer::STEP_TYPE_OBJ, $sType ); + $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aRow = $oDataset->getRow(); + return (int) $aRow['POSITION']; + } catch (Exception $oException) { + throw $Exception; + } + } + + /** + * Reorder the steps positions + * + * @param string $sProcessUID + * @param string $iPosition + * + */ + public function reorderPositions ($sProcessUID, $iPosition, $sType) + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProcessUID ); + $oCriteria->add( StepSupervisorPeer::STEP_TYPE_OBJ, $sType ); + $oCriteria->add( StepSupervisorPeer::STEP_POSITION, $iPosition, '>' ); + $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + var_dump( StepSupervisorPeer::doCount( $oCriteria ) ); + while ($aRow = $oDataset->getRow()) { + var_dump( $aRow ); + echo "\n"; + $this->update( array ('STEP_UID' => $aRow['STEP_UID'],'PRO_UID' => $aRow['PRO_UID'],'STEP_TYPE_OBJ' => $aRow['STEP_TYPE_OBJ'],'STEP_UID_OBJ' => $aRow['STEP_UID_OBJ'],'STEP_POSITION' => $aRow['STEP_POSITION'] - 1 + ) ); + $oDataset->next(); + } + } catch (Exception $oException) { + throw $Exception; + } + } + + public function removeByObject ($sType, $sObjUid) + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepSupervisorPeer::STEP_TYPE_OBJ, $sType ); + $oCriteria->add( StepSupervisorPeer::STEP_UID_OBJ, $sObjUid ); + StepSupervisorPeer::doDelete( $oCriteria ); + } catch (Exception $e) { + throw ($e); + } + } + + public function loadInfo ($sObjUID) + { + + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepSupervisorPeer::STEP_UID_OBJ, $sObjUID ); + $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aRow = $oDataset->getRow(); + return ($aRow); + } +} +// StepSupervisor + diff --git a/workflow/engine/classes/triggers/class.pmSugarFunctions.php b/workflow/engine/classes/triggers/class.pmSugarFunctions.php index 94d0ea1ea..577fb443a 100755 --- a/workflow/engine/classes/triggers/class.pmSugarFunctions.php +++ b/workflow/engine/classes/triggers/class.pmSugarFunctions.php @@ -1,12 +1,13 @@ - 1); - - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - $options['proxy_host'] = $sysConf['proxy_host']; - if ($sysConf['proxy_port'] != '') { - $options['proxy_port'] = $sysConf['proxy_port']; - } - if ($sysConf['proxy_user'] != '') { - $options['proxy_login'] = $sysConf['proxy_user']; - } - if ($sysConf['proxy_pass'] != '') { - $options['proxy_password'] = $sysConf['proxy_pass']; - } - } - - return $options; -} - -/** - * This collection of triggers allows to interact by getting and sending information to SugarCRM - * @class pmSugar - * @name Sugar CRM Triggers - * @icon /images/triggers/icon_SugarCRM.gif - * @className class.pmSugar.pmFunctions.php - */ - -function sugarLogin($sugarSoap, $user, $password) { - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - $auth_array = array ('user_auth' => array ('user_name' => $user, 'password' => md5 ( $password ), 'version' => '1.0' ) ); - $login_results = $client->__SoapCall ( 'login', $auth_array ); - - $session_id = $login_results->id; - $user_guid = $client->__SoapCall ( 'get_user_id', array ($session_id ) ); - return $session_id; -} - -function objectToArray($object) { - if (! is_object ( $object ) && ! is_array ( $object )) { - return $object; - } - if (is_object ( $object )) { - $object = get_object_vars ( $object ); - } - return array_map ( "objectToArray", $object ); -} - -/** - * @method - * - * Gets SugarCRM entry using get_entry web service. - * - * @name GetSugarEntry - * @label Get SugarCRM Entry - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl [^] - * @param string | $user | User - * @param string | $password | Password - * @param string | $module | The name of the module from which to retrieve records. - * @param string | $id | The SugarBean’s ID. - * @param string | $selectedFields | Optional. The list of fields to be returned in the results. - * @param string | $linkNameToFieldsArray | A list of link names and the fields to be returned for each link name. - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarEntries | Sugar Entries (array or object) - * - */ - -function GetSugarEntry($sugarSoap, $user, $password, $module, $id, $selectFields, $linkNameToFieldsArray, $resultType = 'array') { - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - $request_array = array ('session' => $sessionId, 'module_name' => $module, 'id' => $id, - 'select_fields' => $select_fields, 'link_name_to_fields_array' => $linkNameToFieldsArray); - $sugarEntry = $client->__SoapCall ( 'get_entry', $request_array ); - - if($resultType == 'array'){ - $sugarEntry = objectToArray ( $sugarEntry ); - } - - return $sugarEntry; -} - -/** - * @method - * - * Gets SugarCRM entries from the indicated module. - * - * @name GetSugarEntries - * @label Get SugarCRM Entries - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $module | Module - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarEntries | Sugar Entries (array or object) - * - */ - -function GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - $request_array = array ('session' => $sessionId, 'module_name' => $module, 'query' => $query, 'order_by' => $orderBy, 'offset'=>"", 'select_fields'=>"", 'max_result'=>$maxResults ); - $sugarEntriesO = $client->__SoapCall ( 'get_entry_list', $request_array ); - - switch($resultType){ - case 'array':$sugarEntries = objectToArray ( $sugarEntriesO ); break; - case 'object':$sugarEntries = $sugarEntriesO; break; - default: $sugarEntries = objectToArray ( $sugarEntries ); - } - - return $sugarEntries; - -} -/** - * @method - * - * Gets SugarCRM entries from the Calls module - * - * @name GetSugarCalls - * @label Gets SugarCRM entries from the Calls module - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarCalls | Sugar Calls (array or object) - * - */ - -function GetSugarCalls($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $module="Calls"; - return GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType); -} -/** - * @method - * - * Gets SugarCRM entries from the Leads module. - * - * @name GetSugarLeads - * @label Gets SugarCRM entries from the Leads module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarLeads | Sugar Leads (array or object) - * - */ - -function GetSugarLeads($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $module="Leads"; - return GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType); -} -/** - * @method - * - * Gets SugarCRM entries from the Contacts module. - * - * @name GetSugarContacts - * @label Gets SugarCRM entries from the Contacts module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarContacts | Sugar Contacts (array or object) - * - */ - -function GetSugarContacts($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $module="Contacts"; - return GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType); -} -/** - * @method - * - * Gets SugarCRM entries from the Opportunities module. - * - * @name GetSugarOpportunities - * @label Gets SugarCRM entries from the Opportunities module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarAccount | Sugar Opportunities (array or object) - * - */ - -function GetSugarOpportunities($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $module="Opportunities"; - return GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType); -} - -/** - * @method - * - * Gets SugarCRM entries from the Account module. - * - * @name GetSugarAccount - * @label Gets SugarCRM entries from the Account module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $query | Query - * @param string | $orderBy | Order By - * @param string | $selectedFields | Selected Fields - * @param string | $maxResults=50 | Max Results - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarAccount | Sugar Opportunities (array or object) - * - */ - -function GetSugarAccount($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType="array") { - $module="Accounts"; - return GetSugarEntries($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType); -} - - -/** - * @method - * - * Creates SugarCRM entries from the Account module. - * - * @name CreateSugarAccount - * - * @label Creates SugarCRM entries from the Account module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $name | Account name - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarAccount | Sugar Opportunities (array or object) - * - */ -function CreateSugarAccount($sugarSoap, $user, $password, $name, $resultType="array") { - - $module = "Accounts"; - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - $request_array = array ('session' => $sessionId, 'module_name' => $module, 'name_value_list' => array( - array("name" => 'name', "value" => $name ) - ) ); - $sugarEntriesO = $client->__SoapCall ( 'set_entry', $request_array ); - $account_id = $sugarEntriesO ->id; - - switch($resultType){ - case 'array':$sugarEntries = objectToArray ( $sugarEntriesO );break; - case 'object':$sugarEntries = $sugarEntries ;break; - default: $sugarEntries = objectToArray ( $sugarEntries ); - } - //return $sugarEntries; - return $account_id; -} - -/** - * @method - * - * Creates SugarCRM entries from the Account module - * - * @name CreateSugarContact - * - * @label Creates SugarCRM entries from the Account module - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $first_name | First Name - * @param string | $last_name | Last Name - * @param string | $email | Email - * @param string | $title | Title - * @param string | $phone | Phone Work - * @param string | $account_id | Valid id account - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarContact | Sugar Opportunities (array or object) - * - */ -function CreateSugarContact($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType="array") { - - $module = "Contacts"; -/* $aValue = array( + + +function getSoapClientOptions () +{ + $options = array ('trace' => 1); + + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + $options['proxy_host'] = $sysConf['proxy_host']; + if ($sysConf['proxy_port'] != '') { + $options['proxy_port'] = $sysConf['proxy_port']; + } + if ($sysConf['proxy_user'] != '') { + $options['proxy_login'] = $sysConf['proxy_user']; + } + if ($sysConf['proxy_pass'] != '') { + $options['proxy_password'] = $sysConf['proxy_pass']; + } + } + + return $options; +} + +/** + * This collection of triggers allows to interact by getting and sending information to SugarCRM + * @class pmSugar + * + * @name Sugar CRM Triggers + * @icon /images/triggers/icon_SugarCRM.gif + * @className class.pmSugar.pmFunctions.php + */ + +function sugarLogin ($sugarSoap, $user, $password) +{ + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + $auth_array = array ('user_auth' => array ('user_name' => $user,'password' => md5( $password ),'version' => '1.0') ); + $login_results = $client->__SoapCall( 'login', $auth_array ); + $session_id = $login_results->id; + $user_guid = $client->__SoapCall( 'get_user_id', array ($session_id) ); + return $session_id; +} + +function objectToArray ($object) +{ + if (! is_object( $object ) && ! is_array( $object )) { + return $object; + } + if (is_object( $object )) { + $object = get_object_vars( $object ); + } + return array_map( "objectToArray", $object ); +} + +/** + * + * @method Gets SugarCRM entry using get_entry web service. + * + * @name GetSugarEntry + * @label Get SugarCRM Entry + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl [^] + * @param string | $user | User + * @param string | $password | Password + * @param string | $module | The name of the module from which to retrieve records. + * @param string | $id | The SugarBean’s ID. + * @param string | $selectedFields | Optional. The list of fields to be returned in the results. + * @param string | $linkNameToFieldsArray | A list of link names and the fields to be returned for each link name. + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarEntries | Sugar Entries (array or object) + * + */ + +function GetSugarEntry ($sugarSoap, $user, $password, $module, $id, $selectFields, $linkNameToFieldsArray, $resultType = 'array') +{ + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + $request_array = array ('session' => $sessionId,'module_name' => $module,'id' => $id,'select_fields' => $select_fields,'link_name_to_fields_array' => $linkNameToFieldsArray); + $sugarEntry = $client->__SoapCall( 'get_entry', $request_array ); + + if ($resultType == 'array') { + $sugarEntry = objectToArray( $sugarEntry ); + } + + return $sugarEntry; +} + +/** + * + * @method Gets SugarCRM entries from the indicated module. + * + * @name GetSugarEntries + * @label Get SugarCRM Entries + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $module | Module + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarEntries | Sugar Entries (array or object) + * + */ + +function GetSugarEntries ($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + $request_array = array ('session' => $sessionId,'module_name' => $module,'query' => $query,'order_by' => $orderBy,'offset' => "",'select_fields' => "",'max_result' => $maxResults); + $sugarEntriesO = $client->__SoapCall( 'get_entry_list', $request_array ); + + switch ($resultType) { + case 'array': + $sugarEntries = objectToArray( $sugarEntriesO ); + break; + case 'object': + $sugarEntries = $sugarEntriesO; + break; + default: + $sugarEntries = objectToArray( $sugarEntries ); + } + + return $sugarEntries; + +} + +/** + * + * @method Gets SugarCRM entries from the Calls module + * + * @name GetSugarCalls + * @label Gets SugarCRM entries from the Calls module + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarCalls | Sugar Calls (array or object) + * + */ + +function GetSugarCalls ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $module = "Calls"; + return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType ); +} + +/** + * + * @method Gets SugarCRM entries from the Leads module. + * + * @name GetSugarLeads + * @label Gets SugarCRM entries from the Leads module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarLeads | Sugar Leads (array or object) + * + */ + +function GetSugarLeads ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $module = "Leads"; + return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType ); +} + +/** + * + * @method Gets SugarCRM entries from the Contacts module. + * + * @name GetSugarContacts + * @label Gets SugarCRM entries from the Contacts module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarContacts | Sugar Contacts (array or object) + * + */ + +function GetSugarContacts ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $module = "Contacts"; + return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType ); +} + +/** + * + * @method Gets SugarCRM entries from the Opportunities module. + * + * @name GetSugarOpportunities + * @label Gets SugarCRM entries from the Opportunities module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarAccount | Sugar Opportunities (array or object) + * + */ + +function GetSugarOpportunities ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $module = "Opportunities"; + return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType ); +} + +/** + * + * @method Gets SugarCRM entries from the Account module. + * + * @name GetSugarAccount + * @label Gets SugarCRM entries from the Account module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $query | Query + * @param string | $orderBy | Order By + * @param string | $selectedFields | Selected Fields + * @param string | $maxResults=50 | Max Results + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarAccount | Sugar Opportunities (array or object) + * + */ + +function GetSugarAccount ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array") +{ + $module = "Accounts"; + return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType ); +} + +/** + * + * @method Creates SugarCRM entries from the Account module. + * + * @name CreateSugarAccount + * + * @label Creates SugarCRM entries from the Account module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $name | Account name + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarAccount | Sugar Opportunities (array or object) + * + */ +function CreateSugarAccount ($sugarSoap, $user, $password, $name, $resultType = "array") +{ + + $module = "Accounts"; + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + $request_array = array ('session' => $sessionId,'module_name' => $module,'name_value_list' => array (array ("name" => 'name',"value" => $name))); + $sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array ); + $account_id = $sugarEntriesO->id; + + switch ($resultType) { + case 'array': + $sugarEntries = objectToArray( $sugarEntriesO ); + break; + case 'object': + $sugarEntries = $sugarEntries; + break; + default: + $sugarEntries = objectToArray( $sugarEntries ); + } + //return $sugarEntries; + return $account_id; +} + +/** + * + * @method Creates SugarCRM entries from the Account module + * + * @name CreateSugarContact + * + * @label Creates SugarCRM entries from the Account module + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $first_name | First Name + * @param string | $last_name | Last Name + * @param string | $email | Email + * @param string | $title | Title + * @param string | $phone | Phone Work + * @param string | $account_id | Valid id account + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarContact | Sugar Opportunities (array or object) + * + */ +function CreateSugarContact ($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType = "array") +{ + $module = "Contacts"; + /* $aValue = array( array("name" => 'id', "value" => G::generateUniqueID()), array("name" => 'first_name', "value" => $first_name), array("name" => 'last_name', "value" => $last_name), ); -*/ - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - - $request_array = array ('session' => $sessionId, 'module_name' => $module, array( - array("name" => 'first_name',"value" => $first_name), - array("name" => 'last_name',"value" => $last_name), - array("name" => 'email1',"value" => $email), - array("name" => 'title',"value" => $title), - array("name" => 'phone_work',"value" => $phone), - // array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e') - array("name" => 'account_id',"value" => $account_id) - )); - - $sugarEntriesO = $client->__SoapCall ( 'set_entry', $request_array ); - - switch($resultType){ - case 'array':$sugarEntries = objectToArray ( $sugarEntriesO ); break; - case 'object':$sugarEntries = $sugarEntries; break; - default: $sugarEntries = objectToArray ( $sugarEntries ); - } - return $sugarEntries; -} - - -/** - * @method - * - * Creates SugarCRM entries from the Opportunities module. - * - * @name CreateSugarOpportunity - - * @label Creates SugarCRM entries from the Opportunities module. - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $name | Name - * @param string | $account_id | Valid id account - * @param string | $amount | Amount - * @param string | $date_closed | Date Closed - * @param string | $sales_stage | Prospecting, Qualification, Needs Analysis, Value Proposition, Id. Decision Makers, Perception Analysis, Proposal/Price Quote, Negotiation/Review, Closed Won, Closed Lost - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarOpportunity | Sugar Opportunities (array or object) - * - */ -function CreateSugarOpportunity($sugarSoap, $user, $password, $name,$account_id,$amount, $date_closed, $sales_stage,$resultType="array") { -// * @param string | $account_id | Account Id - $module = "Opportunities"; - - /* $aValue = array( + */ + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + + $request_array = array ('session' => $sessionId,'module_name' => $module,array (array ("name" => 'first_name',"value" => $first_name + ),array ("name" => 'last_name',"value" => $last_name + ),array ("name" => 'email1',"value" => $email + ),array ("name" => 'title',"value" => $title + ),array ("name" => 'phone_work',"value" => $phone + ), + // array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e') + array ("name" => 'account_id',"value" => $account_id + ))); + + $sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array ); + + switch ($resultType) { + case 'array': + $sugarEntries = objectToArray( $sugarEntriesO ); + break; + case 'object': + $sugarEntries = $sugarEntries; + break; + default: + $sugarEntries = objectToArray( $sugarEntries ); + } + return $sugarEntries; +} + +/** + * + * @method Creates SugarCRM entries from the Opportunities module. + * + * @name CreateSugarOpportunity + * + * @label Creates SugarCRM entries from the Opportunities module. + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $name | Name + * @param string | $account_id | Valid id account + * @param string | $amount | Amount + * @param string | $date_closed | Date Closed + * @param string | $sales_stage | Prospecting, Qualification, Needs Analysis, Value Proposition, Id. Decision Makers, Perception Analysis, Proposal/Price Quote, Negotiation/Review, Closed Won, Closed Lost + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarOpportunity | Sugar Opportunities (array or object) + * + */ +function CreateSugarOpportunity ($sugarSoap, $user, $password, $name, $account_id, $amount, $date_closed, $sales_stage, $resultType = "array") +{ + // * @param string | $account_id | Account Id + $module = "Opportunities"; + + /* $aValue = array( array("name" => 'id', "value" => G::generateUniqueID()), array("name" => 'name', "value" => $name), array("name" => 'account_name', "value" => $account_name), array("name" => 'amount', "value" => $amount), array("name" => 'date_closed', "value" => $date_closed), array("name" => 'sales_stage', "value" => $sales_stage) - );*/ - - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - - $request_array = array ('session' => $sessionId, 'module_name' => $module, 'name_value_list' =>array( - array('name' => 'name','value' => $name), - array("name" => 'account_id',"value" => $account_id), - array('name' => 'amount','value' => $amount), - array('name' => 'date_closed','value' => $date_closed), - array('name' => 'sales_stage','value' => $sales_stage), - )); - - $sugarEntriesO = $client->__SoapCall ( 'set_entry', $request_array ); - - switch($resultType){ - case 'array':$sugarEntries = objectToArray ( $sugarEntriesO ); break; - case 'object':$sugarEntries = $sugarEntries; break; - default: $sugarEntries = objectToArray ( $sugarEntries ); - } - return $sugarEntries; -} - - - -/** - * @method - * - * Creates SugarCRM entries from the Account module - * - * @name CreateSugarLeads - * - * @label Creates SugarCRM entries from the Account module - * - * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl - * @param string | $user | User - * @param string | $password | Password - * @param string | $first_name | First Name - * @param string | $last_name | Last Name - * @param string | $email | Email - * @param string | $title | Title - * @param string | $phone | Phone Work - * @param string | $account_id | Valid id account - * @param string | $resultType=array | Result type (array or object) - * - * @return array/object | $sugarContact | Sugar Opportunities (array or object) - * - */ -function CreateSugarLeads($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType="array") { - - $module = "Leads"; - $sessionId = sugarLogin ( $sugarSoap, $user, $password ); - $client = new SoapClient ( $sugarSoap, getSoapClientOptions() ); - - $request_array = array ('session' => $sessionId, 'module_name' => $module, array( - array("name" => 'first_name',"value" => $first_name), - array("name" => 'last_name',"value" => $last_name), - array("name" => 'email1',"value" => $email), - array("name" => 'title',"value" => $title), - array("name" => 'phone_work',"value" => $phone), - // array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e') - array("name" => 'account_id',"value" => $account_id) - )); - - $sugarEntriesO = $client->__SoapCall ( 'set_entry', $request_array ); - - switch($resultType){ - case 'array':$sugarEntries = objectToArray ( $sugarEntriesO ); break; - case 'object':$sugarEntries = $sugarEntries; break; - default: $sugarEntries = objectToArray ( $sugarEntries ); - } - return $sugarEntries; -} \ No newline at end of file + );*/ + + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + + $request_array = array ('session' => $sessionId,'module_name' => $module,'name_value_list' => array (array ('name' => 'name','value' => $name + ),array ("name" => 'account_id',"value" => $account_id + ),array ('name' => 'amount','value' => $amount + ),array ('name' => 'date_closed','value' => $date_closed + ),array ('name' => 'sales_stage','value' => $sales_stage + ) + ) + ); + + $sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array ); + + switch ($resultType) { + case 'array': + $sugarEntries = objectToArray( $sugarEntriesO ); + break; + case 'object': + $sugarEntries = $sugarEntries; + break; + default: + $sugarEntries = objectToArray( $sugarEntries ); + } + return $sugarEntries; +} + +/** + * + * @method Creates SugarCRM entries from the Account module + * + * @name CreateSugarLeads + * + * @label Creates SugarCRM entries from the Account module + * + * @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl + * @param string | $user | User + * @param string | $password | Password + * @param string | $first_name | First Name + * @param string | $last_name | Last Name + * @param string | $email | Email + * @param string | $title | Title + * @param string | $phone | Phone Work + * @param string | $account_id | Valid id account + * @param string | $resultType=array | Result type (array or object) + * + * @return array/object | $sugarContact | Sugar Opportunities (array or object) + * + */ +function CreateSugarLeads ($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType = "array") +{ + + $module = "Leads"; + $sessionId = sugarLogin( $sugarSoap, $user, $password ); + $client = new SoapClient( $sugarSoap, getSoapClientOptions() ); + + $request_array = array ('session' => $sessionId,'module_name' => $module,array (array ("name" => 'first_name',"value" => $first_name + ),array ("name" => 'last_name',"value" => $last_name + ),array ("name" => 'email1',"value" => $email + ),array ("name" => 'title',"value" => $title + ),array ("name" => 'phone_work',"value" => $phone + ), + // array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e') + array ("name" => 'account_id',"value" => $account_id + ) + ) + ); + + $sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array ); + + switch ($resultType) { + case 'array': + $sugarEntries = objectToArray( $sugarEntriesO ); + break; + case 'object': + $sugarEntries = $sugarEntries; + break; + default: + $sugarEntries = objectToArray( $sugarEntries ); + } + return $sugarEntries; +} +