/**
  * Adds an Instruction to a Channel.
  *
  * Body of output document takes the form:
  *
  * <code>
  * {"position":"12","channel":"main","data":{"k"=>"v pairs"},"object_type":"Car","communication_key":"g4c667c80947"}
  * </code>
  *
  * @param array $params Expected in the form: 
  *	`array('channelset'=>'name','channel'=>'name','object_type'=>'type of object','data'=>array('k'='v pairs'))
  */
 public function restPostChannelsetChannel($params)
 {
     InstructionControl::startTransaction();
     $channelsetId = $this->getChannelSetId($params['channelset']);
     $userRec = $this->getUser($channelsetId);
     $channelId = InstructionControl::getChannelId($channelsetId, $params['channel']);
     $instructionId = InstructionControl::reserveInstructionId($userRec['id'], $channelId, $params['object_type']);
     $data = array_key_exists('data', $_REQUEST) ? $_REQUEST['data'] : array();
     InstructionControl::addInstructionData($instructionId, $data);
     InstructionControl::completeTransaction();
     $position = InstructionControl::getPositionForInstructionId($instructionId);
     $return = InstructionControl::generateReturnDocument('INSTRUCTION', array(), array(), array(), array(), array('position' => $position, 'channel' => $params['channel'], 'data' => $data, 'object_type' => $params['object_type'], 'communication_key' => $userRec['communication_key']));
     header('HTTP/1.1 201 Created');
     echo json_encode($return);
     if (INSTRUCTIONCONTROL__NOTIFY_OTHER_CLIENTS == 'APE') {
         InstructionControl::notifyOtherClientsApe($params['channelset'], $channelId, $return);
     }
     return true;
 }
 /**
  * This function will send an Instruction (properties) to the other clients
  * on the webpage.
  *
  * @param string $channelset The Channelset name
  * @param string $channelId The Id of the Channel
  * @param array The output from InstructionControl::generateReturnDocument()
  *
  * @see InstructionControl::generateReturnDocument()
  */
 public static function notifyOtherClientsApe($channelset, $channelId, $data)
 {
     $APEserver = 'http://' . self::getOption('APE_CONFIG_SERVER') . '/?';
     $APEPassword = '******';
     if ($channelId === null) {
         $channelsetId = InstructionControl::getChannelsetId($channelset);
         $channelId = InstructionControl::getChannelId($channelsetId, 'main');
     }
     $channelName = self::getChannelname($channelId);
     $cmd = array(array('cmd' => 'inlinepush', 'params' => array('password' => $APEPassword, 'raw' => 'instruction', 'channel' => $channelset . '_' . $channelName, 'data' => $data)));
     $url = $APEserver . rawurlencode(json_encode($cmd));
     $answerJson = file_get_contents($url);
     $answer = array_pop(json_decode($answerJson, true));
     if (!$answer || $answer['data']['value'] != 'ok') {
         throw new Exception("Could not notify other clients " . print_r($cmd, 1) . print_r($answer, 1));
     }
 }
 public function testGetUserByCommunicationKey()
 {
     $csid = InstructionControl::getChannelSetId(genSaneGuid());
     $u = InstructionControl::getUser(null, $n);
     $u = InstructionControl::getUser($u['login_key'], $n);
     InstructionControl::setUserChannelset($u['id'], $csid);
     $v = InstructionControl::getUserByCommunicationKey($csid, $u['communication_key']);
     $this->assertEquals($u, $v);
     $w = InstructionControl::getUserByCommunicationKey($csid, genSaneGuid());
     $this->assertNull($w);
 }
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
header('Content-type: text/html; charset=UTF-8');
session_start();
require_once dirname(__FILE__) . '/../config/icdemo.defines.php';
require_once INSTRUCTIONCONTROL__LIBRARY_DIR . '/markdown.php';
require_once INSTRUCTIONCONTROL__LIBRARY_DIR . '/instructioncontrol/InstructionControl.class.php';
require_once INSTRUCTIONCONTROL__LIBRARY_DIR . '/instructioncontrol/InstructionControl_Utils.class.php';
require_once INSTRUCTIONCONTROL__LIBRARY_DIR . '/dwoo/dwooAutoload.php';
InstructionControl::setOptions(array('APE_CONFIG_SERVER' => INSTRUCTIONCONTROL__APE_CONFIG_SERVER, 'PDO_DATABASE_CONNECTION_STRING' => INSTRUCTIONCONTROL__PDO_DATABASE_CONNECTION_STRING, 'PDO_DATABASE_USERNAME' => INSTRUCTIONCONTROL__PDO_DATABASE_USERNAME, 'PDO_DATABASE_PASSWORD' => INSTRUCTIONCONTROL__PDO_DATABASE_PASSWORD));
class InstructionControl_Utils_Controller_Ic extends InstructionControl_Utils_Controller
{
    protected function acquireData($params, $userRec)
    {
        $data = parent::acquireData($params, $userRec);
        $data['config']['google_maps_api_key'] = GOOGLE_MAPS_API_KEY;
        for ($i = 1; $i <= 7; $i++) {
            $data['help'][] = markdown(file_get_contents('./help_doc_' . $i . '.markdown.text'));
        }
        return $data;
    }
}
$controller = new InstructionControl_Utils_Controller_Ic(new InstructionControl_Utils_ViewRenderer_Dwoo(), 'templ.xhtml');
$routerConfig = array('GET' => array('/:channelset' => array($controller, 'restGetChannelset'), '/:channelset/user' => array($controller, 'restGetChannelsetUser'), '/:channelset/user/:communication_key' => array($controller, 'restGetChannelsetUserCommunicationkey'), '/:channelset/:channel/:instruction' => array($controller, 'restGetChannelsetChannelInstruction'), '/:channelset/:channel' => array($controller, 'restGetChannelsetChannel'), '/' => array($controller, 'restRedirect'), '' => array($controller, 'restRedirect')), 'POST' => array('/:channelset/:channel' => array($controller, 'restPostChannelsetChannel')), 'PUT' => array('/:channelset/user/me' => array($controller, 'restPutChannelsetUserMe')));
$requestMethodOverride = array_key_exists('_REQUEST_METHOD', $_REQUEST) ? $_REQUEST['_REQUEST_METHOD'] : null;