<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# add original article to the notebook
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
$not_access=1;
$granted="I";

require_once('../scripts/includes_mobile.php');
require_once('../../../../db_layer/'.__DBTYPE.'/enterprise.php');

$id = $_POST['group_id'];
$title = $_POST['title'];
$tags = $_POST['tags'];
$type = $_POST['access'];
$description = $_POST['description'];
$clean_description= "<p> ".$description." </p>";

$DB->execute($scrarticlemodifyadd_addArticle, $DB->quote($title),$DB->quote($clean_description),$DB->quote($tags),$DB->escape($type)); 
$noteid = $DB->getId();
$DB->execute($scrarticlemodifyadd_attributeGroupToArticle,
             $DB->escape($id),
             $DB->escape($_SESSION['user_id']),
             $DB->escape($_SESSION['user_id']),
             $DB->escape(1),
             $DB->escape($noteid));

$kws = php_format_tag($tags);
if (isset($tags)) {
	$keyword = explode(",",$tags);
	$keywordSimplified = explode(",",$kws);
	for ($i=0;$i<count($keyword);$i++) {
		$selkw = $keywordSimplified[$i];
		$DB->getResults($scrsendtofriend_getKeyword,$DB->quote($selkw));
		if ($DB->nbResults()==0) {
			$DB->execute($scrsendtofriend_addNewKeyword,$DB->quote($keyword[$i]),$DB->quote($selkw));
			$kwid = $DB->getId();
		}
		else {
			$row = $DB->fetch(0);
			$kwid = $row["id"];
		}
		$DB->freeResults();		
		//notebook article keywords
		$DB->execute($scrnotebookarticleadd_addNewKeywords,$DB->escape($noteid),$kwid);
	}
}

header("location:groupbook.php?id=".$id);
?>