function getOtherImage() { set_time_limit(0); $this->autoRender = false; $sql = "SELECT DoorStyle, ProfileOutsideImage, ProfileInsideImage FROM doorstyles"; $datas = $this->Cabinet->query($sql); App::uses("Door", "Inventory.Model"); $Door_model = new Door(); $i = 1; foreach ($datas as $data) { $door_data = $Door_model->find('first', array('fields' => array('id', 'door_style', 'door_image', 'door_image_dir'), 'conditions' => array('Door.door_style' => $data['doorstyles']['DoorStyle']), 'recursive' => -1)); $id = $door_data['Door']['id']; if (!empty($data['doorstyles']['ProfileOutsideImage'])) { mkdir(WWW_ROOT . 'files' . DS . 'door' . DS . 'outside_profile_image' . DS . $door_data['Door']['id'], 0777, TRUE); file_put_contents(WWW_ROOT . "files/door/outside_profile_image/{$id}/thumb_outside_profile_image.jpg", $data['doorstyles']['ProfileOutsideImage']); file_put_contents(WWW_ROOT . "files/door/outside_profile_image/{$id}/xvga_outside_profile_image.jpg", $data['doorstyles']['ProfileOutsideImage']); file_put_contents(WWW_ROOT . "files/door/outside_profile_image/{$id}/vga_outside_profile_image.jpg", $data['doorstyles']['ProfileOutsideImage']); $out_door_image_data['Door']['id'] = $door_data['Door']['id']; $out_door_image_data['Door']['outside_profile_image'] = "outside_profile_image.jpg"; $out_door_image_data['Door']['outside_profile_image_dir'] = $id; $Door_image_model = new Door(); $Door_image_model->save($out_door_image_data); } if (!empty($data['doorstyles']['ProfileInsideImage'])) { mkdir(WWW_ROOT . 'files' . DS . 'door' . DS . 'inside_profile_image' . DS . $door_data['Door']['id'], 0777, TRUE); file_put_contents(WWW_ROOT . "files/door/inside_profile_image/{$id}/thumb_inside_profile_image.jpg", $data['doorstyles']['ProfileInsideImage']); file_put_contents(WWW_ROOT . "files/door/inside_profile_image/{$id}/xvga_inside_profile_image.jpg", $data['doorstyles']['ProfileInsideImage']); file_put_contents(WWW_ROOT . "files/door/inside_profile_image/{$id}/vga_inside_profile_image.jpg", $data['doorstyles']['ProfileInsideImage']); $in_door_image_data['Door']['id'] = $door_data['Door']['id']; $in_door_image_data['Door']['inside_profile_image'] = "inside_profile_image.jpg"; $in_door_image_data['Door']['inside_profile_image_dir'] = $id; $Door_image_model = new Door(); $Door_image_model->save($in_door_image_data); } } }
function door_action_door() { global $_, $conf, $myUser; switch ($_['action']) { case 'door_delete_door': if ($myUser->can('porte', 'd')) { $doorManager = new Door(); $doorManager->delete(array('id' => $_['id'])); } header('location:setting.php?section=door'); break; case 'door_add_door': if ($myUser->can('porte', 'c')) { $door = new Door(); $door->setName($_['nameDoor']); $door->setDescription($_['descriptionDoor']); $door->setPinRelay($_['pinDoorRelay']); $door->setPinCaptor($_['pinDoorCaptor']); $door->setRoom($_['roomDoor']); $door->save(); } header('location:setting.php?section=door'); break; case 'door_get_state': if ($myUser->can('porte', 'r')) { $door = new Door(); $door = $door->getById($_['engine']); $cmd = '/usr/local/bin/gpio mode ' . $door->getPinCaptor() . ' in'; system($cmd, $out); $cmd = '/usr/local/bin/gpio read ' . $door->getPinCaptor(); exec($cmd, $out); if (!isset($_['webservice'])) { echo $out[0]; } else { $affirmation = trim($out[0]) ? 'Ouvert' : 'Fermé'; $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation))); $json = json_encode($response); echo $json == '[]' ? '{}' : $json; } } break; case 'door_change_state': global $_, $myUser; if ($myUser->can('porte', 'u')) { $door = new Door(); $door = $door->getById($_['engine']); $cmd = '/usr/local/bin/gpio mode ' . $door->getPinRelay() . ' out'; system($cmd, $out); $cmd = '/usr/local/bin/gpio write ' . $door->getPinRelay() . ' ' . $_['state']; system($cmd, $out); //TODO change bdd state if (!isset($_['webservice'])) { header('location:index.php?module=room&id=' . $door->getRoom()); } else { $affirmations = array('A vos ordres!', 'Bien!', 'Oui commandant!', 'Avec plaisir!', 'J\'aime vous obéir!', 'Avec plaisir!', 'Certainement!', 'Je fais ça sans tarder!', 'Avec plaisir!', 'Oui chef!'); $affirmation = $affirmations[rand(0, count($affirmations) - 1)]; $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation))); $json = json_encode($response); echo $json == '[]' ? '{}' : $json; } } else { $response = array('responses' => array(array('type' => 'talk', 'sentence' => 'Je ne vous connais pas, je refuse de faire ça!'))); echo json_encode($response); } break; } }