Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_login_ipb.inc
1 <?php
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
20 
21 
34 {
35 
36 
46  function __construct($assetid=0)
47  {
48  parent::__construct($assetid);
49 
50  }//end constructor
51 
52 
70  public static function execute($settings, &$state)
71  {
72  // check settings, state
73  if (empty($settings['ipbsdk_path']) || !file_exists($settings['ipbsdk_path'])) {
74  // if no settings, fail
75  return FALSE;
76  }
77 
78  // state, user asset
79  if (empty($state['asset'])) {
80  // grab the asset if assetid is given, but not the asset.
81  if (empty($state['assetid'])) {
82  return FALSE;
83  } else {
84  $state['asset'] =& $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
85  }
86  }
87 
88  $username = $state['asset']->attr('username');
89 
90  // if the password is passed from $settings, use it.
91  if (isset($settings['password']) && !empty($settings['password'])) {
92  $password = $settings['password'];
93  } else {
94  $password = $state['event']['data']['password'];
95  }
96 
97  // Load and Start IPB SDK
98  if (!file_exists($settings['ipbsdk_path'].'/ipbsdk_class.inc.php')) {
99  trigger_localised_error('IPB0001', E_USER_WARNING);
100  return FALSE;
101  }
102  require_once $settings['ipbsdk_path'].'/ipbsdk_class.inc.php';
103 
104  // We have to supress error reporting level since IPB and IPBSDK
105  // generates many PHP Notice warnings
106  $old_reporting_level = error_reporting(0);
107  $SDK = new IPBSDK();
108  if (!$SDK->login($username, $password, 1)) {
109  // Do we want any error reporting?
110  }
111  error_reporting($old_reporting_level);
112 
113  return TRUE;
114 
115  }//end execute()
116 
117 
128  public static function getInterface($settings, $prefix, $write_access=FALSE)
129  {
130  $ipbsdk_path = array_get_index($settings, 'ipbsdk_path', '');
131  ob_start();
132  ?>
133  <table border="0">
134  <tr>
135  <td valign="top"><b><?php echo translate('ipb_path_to_ipbsdk'); ?></b></td>
136  <td valign="top" style="padding-bottom: 10px;"><?php
137  // level
138  if ($write_access) {
139  echo text_box($prefix.'[ipbsdk_path]', $ipbsdk_path, '50');
140  } else {
141  echo $ipbsdk_path.'&nbsp;';
142  }
143  ?>
144  <br /><b>Note:</b>&nbsp;Please make sure the IPB SDK version is compatible with the installed IPB.
145  <br />For more information, please visit <a href="http://ipbsdk.sourceforge.net/">the IPBSDK website</a>
146  </td>
147  </tr>
148  </table>
149  <?php
150 
151  return ob_get_clean();
152 
153  }//end getInterface()
154 
155 
167  public static function processInterface(&$settings, $request_data)
168  {
169  $ipbsdk_path = array_get_index($request_data, 'ipbsdk_path', '');
170  $ipbsdk_path = trim($ipbsdk_path);
171  if ($ipbsdk_path == '') {
172  trigger_localised_error('IPB0002', E_USER_WARNING);
173  return FALSE;
174  }
175  $settings['ipbsdk_path'] = $ipbsdk_path;
176 
177  return FALSE;
178 
179  }//end processInterface()
180 
181 
191  public static function getLocks($settings, &$state)
192  {
193  return Array(
194  $state['assetid'] => Array(
195  'attributes',
196  ),
197  );
198 
199  }//end getLocks()
200 
201 
202 }//end class