/**
	 * Add webpage
	 *
	 * @access public
	 * @param void
	 * @return null
	 */
	function add() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$this->setTemplate('add');
		
		$notAllowedMember = '';
		if(!ProjectWebpage::canAdd(logged_user(), active_context(), $notAllowedMember)) {
			if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
			else flash_error(lang('no context permissions to add',lang("webpages"), $notAllowedMember));
			ajx_current("empty");
			return;
		} // if

		$webpage = new ProjectWebpage();

		$webpage_data = array_var($_POST, 'webpage');
		
		if(is_array(array_var($_POST, 'webpage'))) {
			try {
				if(substr_utf($webpage_data['url'],0,7) != 'http://' && substr_utf($webpage_data['url'],0,7) != 'file://' && substr_utf($webpage_data['url'],0,8) != 'https://' && substr_utf($webpage_data['url'],0,6) != 'about:' && substr_utf($webpage_data['url'],0,6) != 'ftp://') {
					$webpage_data['url'] = 'http://' . $webpage_data['url'];
				}
				
				$webpage->setFromAttributes($webpage_data);
				
				DB::beginWork();
				$webpage->save();

				$member_ids = json_decode(array_var($_POST, 'members'));
				
				//link it!
                                $object_controller = new ObjectController();
                                $object_controller->add_subscribers($webpage);
                                $object_controller->add_to_members($webpage, $member_ids);
                                $object_controller->link_to_new_object($webpage);
				$object_controller->add_subscribers($webpage);
                                $object_controller->add_custom_properties($webpage);

				ApplicationLogs::createLog($webpage, ApplicationLogs::ACTION_ADD);
				DB::commit();


				flash_success(lang('success add webpage', $webpage->getObjectName()));
				ajx_current("back");
				// Error...
			} catch(Exception $e) {
				DB::rollback();
				flash_error($e->getMessage());
				ajx_current("empty");
			}

		}

		tpl_assign('webpage', $webpage);
		tpl_assign('webpage_data', $webpage_data);
	} // add
 /**
  * Add webpage
  *
  * @access public
  * @param void
  * @return null
  */
 function add()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add');
     if (!ProjectWebpage::canAdd(logged_user(), active_or_personal_project())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $webpage = new ProjectWebpage();
     $webpage_data = array_var($_POST, 'webpage');
     if (!is_array($webpage_data)) {
         $webpage_data = array('milestone_id' => array_var($_GET, 'milestone_id'));
         // array
     }
     // if
     if (is_array(array_var($_POST, 'webpage'))) {
         try {
             if (substr_utf($webpage_data['url'], 0, 7) != 'http://' && substr_utf($webpage_data['url'], 0, 7) != 'file://' && substr_utf($webpage_data['url'], 0, 8) != 'https://' && substr_utf($webpage_data['url'], 0, 6) != 'about:' && substr_utf($webpage_data['url'], 0, 6) != 'ftp://') {
                 $webpage_data['url'] = 'http://' . $webpage_data['url'];
             }
             $webpage->setFromAttributes($webpage_data);
             $webpage->setIsPrivate(false);
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $webpage->setIsPrivate(false);
             }
             // if
             DB::beginWork();
             $webpage->save();
             $webpage->setTagsFromCSV(array_var($webpage_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($webpage);
             $object_controller->link_to_new_object($webpage);
             $object_controller->add_subscribers($webpage);
             $object_controller->add_custom_properties($webpage);
             ApplicationLogs::createLog($webpage, $webpage->getWorkspaces(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             flash_success(lang('success add webpage', $webpage->getTitle()));
             ajx_current("back");
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
     tpl_assign('webpage', $webpage);
     tpl_assign('webpage_data', $webpage_data);
 }