Example #1
0
 /**
  * 
  * 
  * @return string
  */
 public function generate()
 {
     $name = $this->_name;
     $descrip = $this->_descrip;
     $appurl = $this->_appurl;
     $appsupport = $this->_appsupport;
     $username = $this->_username;
     $fileid = $this->_fileid;
     $ownerid = $this->_ownerid;
     $qbtype = $this->_qbtype;
     $readonly = $this->_readonly;
     $run_every_n_seconds = $this->_run_every_n_seconds;
     $personaldata = $this->_personaldata;
     $unattendedmode = $this->_unattendedmode;
     $authflags = $this->_authflags;
     $notify = $this->_notify;
     $appdisplayname = $this->_appdisplayname;
     $appuniquename = $this->_appuniquename;
     $appid = $this->_appid;
     /*
     AppDisplayName
     AppUniqueName
     AuthFlags
     	- 0x0 (all, default)
     	- 0x0 (All, default) 
     	- 0x1 (SupportQBSimpleStart) 
     	- 0x2 (SupportQBPro) 
     	- 0x4 (SupportQBPremier) 
     	- 0x8 (SupportQBEnterprise)
     Notify			true or false
     PersonalDataPref
     	- pdpNotNeeded
     	- pdpOptional
     	- pdpRequired
     Style	(do not support, package only supports default style)
     UnattendedModePref
     	- umpRequired
     	- umpOptional
     CertURL
     */
     if ($run_every_n_seconds and !is_numeric($run_every_n_seconds)) {
         $run_every_n_seconds = QuickBooks_Utilities::intervalToSeconds($run_every_n_seconds);
     }
     $ownerid = '{' . trim($ownerid, '{}') . '}';
     $fileid = '{' . trim($fileid, '{}') . '}';
     $xml = '';
     $xml .= '<?xml version="1.0"?>' . QUICKBOOKS_CRLF;
     $xml .= '<QBWCXML>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<AppName>' . htmlspecialchars($name) . '</AppName>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<AppID>' . htmlspecialchars($appid) . '</AppID>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<AppURL>' . htmlspecialchars($appurl) . '</AppURL>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<AppDescription>' . htmlspecialchars($descrip) . '</AppDescription>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<AppSupport>' . htmlspecialchars($appsupport) . '</AppSupport>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<UserName>' . htmlspecialchars($username) . '</UserName>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<OwnerID>' . $ownerid . '</OwnerID>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<FileID>' . $fileid . '</FileID>' . QUICKBOOKS_CRLF;
     $xml .= "\t" . '<QBType>' . $qbtype . '</QBType>' . QUICKBOOKS_CRLF;
     if ($personaldata != QuickBooks_WebConnector_QWC::PERSONALDATA_DEFAULT) {
         $xml .= "\t" . '<PersonalDataPref>' . $personaldata . '</PersonalDataPref>' . QUICKBOOKS_CRLF;
     }
     if ($unattendedmode != QuickBooks_WebConnector_QWC::UNATTENDEDMODE_DEFAULT) {
         $xml .= "\t" . '<UnattendedModePref>' . $unattendedmode . '</UnattendedModePref>' . QUICKBOOKS_CRLF;
     }
     if ($authflags != QuickBooks_WebConnector_QWC::SUPPORTED_DEFAULT) {
         $xml .= "\t" . '<AuthFlags>' . $authflags . '</AuthFlags>' . QUICKBOOKS_CRLF;
     }
     if ($notify) {
         $xml .= "\t" . '<Notify>true</Notify>' . QUICKBOOKS_CRLF;
     } else {
         $xml .= "\t" . '<Notify>false</Notify>' . QUICKBOOKS_CRLF;
     }
     if ($appdisplayname) {
         $xml .= "\t" . '<AppDisplayName>' . $appdisplayname . '</AppDisplayName>' . QUICKBOOKS_CRLF;
     }
     if ($appuniquename) {
         $xml .= "\t" . '<AppUniqueName>' . $appuniquename . '</AppUniqueName>' . QUICKBOOKS_CRLF;
     }
     if ((int) $run_every_n_seconds > 0 and (int) $run_every_n_seconds < 60) {
         $xml .= "\t" . '<Scheduler>' . QUICKBOOKS_CRLF;
         $xml .= "\t" . "\t" . '<RunEveryNSeconds>' . (int) $run_every_n_seconds . '</RunEveryNSeconds>' . QUICKBOOKS_CRLF;
         $xml .= "\t" . '</Scheduler>' . QUICKBOOKS_CRLF;
     } else {
         if ((int) $run_every_n_seconds >= 60) {
             $xml .= "\t" . '<Scheduler>' . QUICKBOOKS_CRLF;
             $xml .= "\t" . "\t" . '<RunEveryNMinutes>' . floor($run_every_n_seconds / 60) . '</RunEveryNMinutes>' . QUICKBOOKS_CRLF;
             $xml .= "\t" . '</Scheduler>' . QUICKBOOKS_CRLF;
         }
     }
     if ($readonly) {
         $xml .= "\t" . '<IsReadOnly>true</IsReadOnly>' . QUICKBOOKS_CRLF;
     } else {
         $xml .= "\t" . '<IsReadOnly>false</IsReadOnly>' . QUICKBOOKS_CRLF;
     }
     $xml .= '</QBWCXML>';
     return trim($xml);
 }
Example #2
0
 /**
  * Register a recurring event 
  * 
  * Recurring events are actions that get queued up to run once every so 
  * often. So, for instance, if you want to make sure you issue a 
  * CustomerQuery every day, you can register a recurring event that occurs 
  * every day, and then the SOAP server/Web Connector will try to make sure 
  * that it gets run every day. 
  * 
  * Note that the SOAP server can't guarantee that an action will occur 
  * every interval *unless* the Web Connector is set to connect at that same 
  * interval or (preferably) more often.
  * 
  * @param mixed $run_every		This can be either an integer number of seconds, or a string like: "15 minutes", "2 days", "hour", etc.
  * @param string $action		The QuickBooks action you want to execute
  * @param mixed $ident			An optional ident string (say you wanted to do a CustomerQuery for customer #14 every 15 minutes, you'd pass CustomerQuery for the action, and 14 for the ident)
  * @param integer $priority		The priority of the action (higher priorities run first)
  * @param mixed $extra			Any extra data to include for the request handler
  * @param string $user			The username of the QuickBooks Web Connector user this event should be registered for
  * @param boolean $replace		Whether or not this should replace any other recurring events with this action/ident
  * @return boolean 
  */
 public function recurring($run_every, $action, $ident = null, $priority = 0, $extra = null, $user = null, $qbxml = null, $replace = true)
 {
     $run_every = QuickBooks_Utilities::intervalToSeconds($run_every);
     if (!strlen($ident)) {
         $tmp = array_merge(array('a', 'z'), range(0, 9));
         shuffle($tmp);
         $ident = substr(implode('', $tmp), 0, 8);
     }
     if ($this->_driver) {
         /*
         if (!$user)
         {
         	$user = $this->_driver->authDefault();
         }
         */
         // Use the default user (provided in __construct) if none is given
         if (!$user) {
             $user = $this->_user;
         }
         return $this->_driver->recurEnqueue($user, $run_every, $action, substr($ident, 0, 40), $replace, $priority, $extra, $qbxml);
     }
     return false;
 }
Example #3
0
 /**
  * 
  * 
  * You can run this server in one of three modes:
  * 	- QUICKBOOKS_SERVER_SQL_MODE_READONLY: Data will only be read from 
  * 		QuickBooks; changes to data in the SQL database will never be 
  * 		pushed back to QuickBooks. 
  * 	- QUICKBOOKS_SERVER_SQL_MODE_WRITEONLY: Data will only be pushed to 
  * 		QuickBooks, and nothing that already exists in QuickBooks will be 
  * 		imported into the SQL database.
  * 	- QUICKBOOKS_SERVER_SQL_MODE_READWRITE: The server will do it's best to 
  * 		try to import all QuickBooks data into the SQL database, and then 
  * 		push changes that occur in either location to the other location. 
  * 		The server will try to syncronise the two locations as much as is 
  * 		possible. 
  * 
  * @param string $dsn_or_conn		DSN-style connection string or an already opened connection to the driver
  * @param string $how_often			The maximum time we wait between updates/syncs (you can use any valid interval: "1 hour", "15 minutes", 60, etc.)
  * @param char $mode				The mode the server should run in (see constants above)
  * @param char $conflicts			The steps towards update conflict resolution the server should take (see constants above)
  * @param mixed $users				The user (or an array of users) who will be using the SQL server
  * @param array $map				
  * @param array $onerror			
  * @param string $wsdl				
  * @param array $soap_options		
  * @param array $handler_options	
  * @param array $driver_options		
  */
 public function __construct($dsn_or_conn, $how_often, $mode, $delete, $conflicts, $users = null, $map = array(), $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $sql_options = array(), $callback_options = array())
 {
     // $dsn_or_conn, $map, $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
     if (!is_array($users)) {
         $users = array($users);
     }
     // Map of callback handlers
     $sql_map = array();
     foreach (get_class_methods('QuickBooks_Server_SQL_Callbacks') as $method) {
         if (strtolower(substr($method, -7)) == 'request') {
             $action = substr($method, 0, -7);
             $sql_map[$action] = array('QuickBooks_Server_SQL_Callbacks::' . $action . 'Request', 'QuickBooks_Server_SQL_Callbacks::' . $action . 'Response');
         }
     }
     // Default error handlers
     $sql_onerror = array('*' => 'QuickBooks_Server_SQL_Errors::catchall');
     $sql_onerror = $this->_merge($sql_onerror, $onerror, false);
     // Default hooks
     $sql_hooks = array(QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS => array('QuickBooks_Server_SQL_Callbacks::onAuthenticate'));
     // Merge with user-defined hooks
     $sql_hooks = $this->_merge($hooks, $sql_hooks, true);
     // @TODO Prefix these with _ so that people don't accidentally overwrite them
     $sql_callback_options = array('hooks' => $sql_hooks, 'conflicts' => $conflicts, 'mode' => $mode, 'delete' => $delete, 'recur' => QuickBooks_Utilities::intervalToSeconds($how_often), 'map' => $sql_map);
     //print_r($sql_options);
     //exit;
     $defaults = $this->_sqlDefaults($sql_options);
     $sql_callback_options['_only_query'] = $defaults['only_query'];
     $sql_callback_options['_dont_query'] = $defaults['dont_query'];
     $sql_callback_options['_only_add'] = $defaults['only_add'];
     $sql_callback_options['_dont_add'] = $defaults['dont_add'];
     $sql_callback_options['_only_modify'] = $defaults['only_modify'];
     $sql_callback_options['_dont_modify'] = $defaults['dont_modify'];
     // Merge default values with passed in values
     //	(in this case, we are *required* to have these values present, so
     //	we make sure that the SQL options override any user-defined options
     $sql_callback_options = $this->_merge($callback_options, $sql_callback_options, false);
     // Initialize the Driver singleton
     $Driver = QuickBooks_Driver_Singleton::getInstance($dsn_or_conn, $driver_options, $sql_hooks, $log_level);
     // $dsn_or_conn, $map, $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
     parent::__construct($dsn_or_conn, $sql_map, $sql_onerror, $sql_hooks, $log_level, $soap, $wsdl, $soap_options, $handler_options, $driver_options, $sql_callback_options);
 }