public static function update($id, $data)
 {
     session_start();
     $headers = apache_request_headers();
     $token = $headers['X-Auth-Token'];
     if ($token != $_SESSION['form_token']) {
         header('Invalid CSRF Token', true, 401);
         return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT);
     } else {
         if (isset($data['name']) && empty($data['name'])) {
             return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Location Name is required'), JSON_PRETTY_PRINT);
         } else {
             if (isset($data['x_coord']) && empty($data['x_coord'])) {
                 return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'X Coordinate is required'), JSON_PRETTY_PRINT);
             } else {
                 if (isset($data['y_coord']) && empty($data['y_coord'])) {
                     return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Y Coordinate is required'), JSON_PRETTY_PRINT);
                 } else {
                     $var = ['name' => $data['name'], 'x' => $data['x_coord'], 'y' => $data['y_coord'], 'description' => $data['description'], 'landarea' => $data['landarea'], 'image_path' => $data['image_path']];
                     Location::update($id, $var);
                 }
             }
         }
     }
 }
Beispiel #2
0
   /**
    * sons / ancestors for CommonTreeDropdown
    */
   public function testTree() {

      $entity = $this->sharedFixture['entity'][0];
      $loc = new Location();

      // A
      $id[0] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'A'));
      $this->assertGreaterThan(0, $id[0]);

      // A > AA
      $id[1] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'AA'));
      $this->assertGreaterThan(0, $id[1]);
      $this->assertTrue($loc->getFromDB($id[1]));
      $this->assertEquals('A > AA', $loc->fields['completename']);

      // A > BB
      $id[2] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'BB'));
      $this->assertGreaterThan(0, $id[2]);
      $this->assertTrue($loc->getFromDB($id[2]));
      $this->assertEquals('A > BB', $loc->fields['completename']);

      // Sons of A (A, AA, BB)
      $sons = getSonsOf('glpi_locations',$id[0]);
      $this->assertEquals(3, count($sons));
      $this->assertArrayHasKey($id[0], $sons);
      $this->assertArrayHasKey($id[1], $sons);
      $this->assertArrayHasKey($id[2], $sons);

      // Ancestors of A (none)
      $parent = getAncestorsOf('glpi_locations', $id[0]);
      $this->assertEquals(0, count($parent));

      // Ancestors of AA (A)
      $parent = getAncestorsOf('glpi_locations', $id[1]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // Ancestors of BB (none)
      $parent = getAncestorsOf('glpi_locations', $id[2]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // B
      $id[3] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'B'));
      $this->assertGreaterThan(0, $id[3]);

      // B > CC
      $id[4] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[3],
                               'name'         => 'CC'));
      $this->assertGreaterThan(0, $id[4]);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('B > CC', $loc->fields['completename']);

      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(2, count($sons));
      $this->assertArrayHasKey($id[4], $sons);

      // B > CC > XXX
      $id[5] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[4],
                               'name'         => 'XXX'));
      $this->assertGreaterThan(0, $id[5]);
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('B > CC > XXX', $loc->fields['completename']);

      // B > CC => A > CC
      $res = $loc->update(array('id'           => $id[4],
                                'locations_id' => $id[0]));
      $this->assertTrue($res);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('A > CC', $loc->fields['completename']);

      // B > CC > XXX => A > CC > XXX
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('A > CC > XXX', $loc->fields['completename']);

      // New parent of CC (A)
      $parent = getAncestorsOf('glpi_locations', $id[4]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // New sons of B (only B)
      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(1, count($sons));
      $this->assertArrayHasKey($id[3], $sons);

      // New sons of A (A, AA, BB, CC)
      $sons = getSonsOf('glpi_locations',$id[0]);
      $this->assertEquals(5, count($sons));
      $this->assertArrayHasKey($id[4], $sons);
      $this->assertArrayHasKey($id[5], $sons);

      // Rename A => C
      $res = $loc->update(array('id'   => $id[0],
                                'name' => 'C'));
      $this->assertTrue($res);

      // Check complete name of sons
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('C > CC', $loc->fields['completename']);

      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('C > CC > XXX', $loc->fields['completename']);
      $this->assertEquals(3, $loc->fields['level']);

      // Delete CC and move child under B
      $res = $loc->delete(array('id' => $id[4],
                                '_replace_by' => $id[3]));
      $this->assertTrue($res);

      // Sons of B (B and XXX)
      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(2, count($sons));
      $this->assertArrayHasKey($id[5], $sons);

      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('B > XXX', $loc->fields['completename']);
      $this->assertEquals(2, $loc->fields['level']);
   }
Beispiel #3
0
 function resetMoreDetailsToDefault()
 {
     $location = new Location();
     $locationId = $_REQUEST['id'];
     $location->locationId = $locationId;
     if ($location->find(true)) {
         $location->clearMoreDetailsOptions();
         $defaultOptions = array();
         require_once ROOT_DIR . '/RecordDrivers/Interface.php';
         $defaultMoreDetailsOptions = RecordInterface::getDefaultMoreDetailsOptions();
         $i = 0;
         foreach ($defaultMoreDetailsOptions as $source => $defaultState) {
             $optionObj = new LocationMoreDetails();
             $optionObj->locationId = $locationId;
             $optionObj->collapseByDefault = $defaultState == 'closed';
             $optionObj->source = $source;
             $optionObj->weight = $i++;
             $defaultOptions[] = $optionObj;
         }
         $location->moreDetailsOptions = $defaultOptions;
         $location->update();
         $_REQUEST['objectAction'] = 'edit';
     }
     $structure = $this->getObjectStructure();
     header("Location: /Admin/Locations?objectAction=edit&id=" . $locationId);
 }
 /**
  * test updating a Location that does not exist
  *
  * @expectedException PDOException
  **/
 public function testUpdateInvalidLocation()
 {
     // create a Location and try to update it without actually inserting it
     $location = new Location(null, $this->VALID_storageCode, $this->VALID_description);
     $location->update($this->getPDO());
 }
 /**
  * Allows a user to edit a location.
  *
  */
 public function editAction()
 {
     $messages = array();
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->locationId)) {
         throw new Ot_Exception_Input('msg-error-locationIdNotSet');
     }
     $location = new Location();
     $thisLocation = $location->find($get->locationId);
     if (is_null($thisLocation)) {
         throw new Ot_Exception_Data('msg-error-noLocation');
     }
     $form = $location->form($thisLocation->toArray());
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $data = array('locationId' => $form->getValue('locationId'), 'name' => $form->getValue('name'), 'locationType' => $form->getValue('locationType'), 'capacity' => $form->getValue('capacity'), 'description' => $form->getValue('description'), 'address' => $form->getValue('address'), 'status' => $form->getValue('status'));
             $location->update($data, null);
             $trigger = new Ot_Trigger();
             $data['accountId'] = Zend_Auth::getInstance()->getIdentity()->accountId;
             $trigger->setVariables($data);
             $trigger->dispatch('Location_Edit');
             $this->_helper->flashMessenger->addMessage('msg-info-locationModified');
             $this->_helper->redirector->gotoUrl('/workshop/location/details/?locationId=' . $form->getValue('locationId'));
         } else {
             $messages[] = "msg-error-formSubmitProblem";
         }
     }
     $this->view->messages = $messages;
     $this->view->form = $form;
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.wysiwyg.js');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.wysiwyg.css');
     $this->_helper->pageTitle('workshop-location-edit:title');
 }
Beispiel #6
0
 public function save_locationorder()
 {
     $location_array = $_POST['location_id'];
     $fnb_id = $_POST['fnb_id'];
     $order_array = $_POST['order'];
     $locationImg = new Location();
     foreach ($location_array as $key => $value) {
         $locationimg_id = $value;
         $locationimg_order = $order_array[$key];
         $locationImg->update('Location', array('sequence' => $locationimg_order), 'id=' . $locationimg_id);
     }
     Flash::set('success', __('The location sequence has been saved.'));
     redirect(get_url('fnb/edit/' . $fnb_id));
 }
 public function ajax_add_entry()
 {
     $response = array('success' => 0, 'error' => 'Something went wrong. Please try again.');
     if (wp_verify_nonce($_POST['entry_nonce'], 'entry-nonce')) {
         $miles = strlen(trim($_POST['miles'])) > 0 && is_numeric($_POST['miles']) ? abs(trim($_POST['miles'])) : 1;
         $location = new Location();
         if ($_POST['location_id'] > 0) {
             $location->id = $_POST['location_id'];
             $location->read();
             if (!$location->user_id == get_current_user_id()) {
                 $location->id = 0;
             }
         }
         if ($location->id == 0) {
             $location->user_id = get_current_user_id();
             $location->title = strlen(trim($_POST['title'])) > 0 ? trim($_POST['title']) : 'New Location';
             $location->miles = $miles;
             $location_id = Location::checkTitle($location->user_id, $location->title);
             if ($location_id > 0) {
                 $location->id = $location_id;
                 $location->update();
             } else {
                 $location->create();
             }
         }
         $entry = new Entry();
         $entry->user_id = get_current_user_id();
         $entry->entry_date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
         $entry->mode = $_POST['mode'];
         $entry->miles = $miles;
         $entry->location = $location;
         $entry->create();
         if ($entry->id > 0) {
             $response['success'] = 1;
             $response['id'] = $entry->id;
             $response['title'] = $entry->location->title;
             $response['miles'] = number_format($entry->miles, 2);
             $response['day'] = $_POST['day'];
         }
     }
     header('Content-Type: application/json');
     echo json_encode($response);
     exit;
 }
Beispiel #8
0
            $location->insert($pdo);
            $reply->data = "Location created OK";
            // delete an existing Location
        } else {
            if ($method === "DELETE") {
                verifyXsrf();
                $location = Location::getLocationByLocationId($pdo, $locationId);
                $location->delete($pdo);
                $reply->data = "Location deleted OK";
                // put to an existing Location
            } else {
                if ($method === "PUT") {
                    // convert PUTed JSON to an object
                    verifyXsrf();
                    $requestContent = file_get_contents("php://input");
                    $requestObject = json_decode($requestContent);
                    $location = new Location($locationId, $requestObject->storageCode, $requestObject->description);
                    $location->update($pdo);
                    $reply->data = "Location Updated Ok";
                }
            }
        }
    }
    // create an exception to pass back to the RESTful caller
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
    unset($reply->data);
}
header("Content-type: application/json");
echo json_encode($reply);
Beispiel #9
0
                            }
                        }
                    }
                }
            }
        }
        if ($_GET['type'] == 'location') {
            $location = new Location($connection);
            if (isset($_POST['submit'])) {
                if ($_GET['action'] == 'add') {
                    $location->loadFromPage();
                    $location->insert();
                } else {
                    if ($_GET['action'] == 'edit') {
                        $location->loadFromPage();
                        $location->update();
                    }
                }
            } else {
                if ($_GET['action'] == 'edit') {
                    $location->loadEntry($_GET['index']);
                }
                $location->printForm($_GET['action']);
            }
        }
    }
} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage();
}
echo "\n<center>\n<br><br>";
$webpage->addURL("index.php?action=add&type=asset", "Add a new asset");
Beispiel #10
0
 function resetFacetsToDefault()
 {
     $location = new Location();
     $locationId = $_REQUEST['id'];
     $location->locationId = $locationId;
     if ($location->find(true)) {
         $location->clearFacets();
         $defaultFacets = Location::getDefaultFacets($locationId);
         $location->facets = $defaultFacets;
         $location->update();
         $_REQUEST['objectAction'] = 'edit';
     }
     $structure = $this->getObjectStructure();
     header("Location: /Admin/Locations?objectAction=edit&id=" . $libraryId);
 }