Skip to content

Commit

Permalink
Manage project category
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-florian committed Aug 29, 2016
1 parent f7c89b0 commit a4ce756
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 88 deletions.
13 changes: 12 additions & 1 deletion htdocs/categories/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin;
if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin;
if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin;
if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin;
}

if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin;
Expand Down Expand Up @@ -116,6 +117,11 @@
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
exit;
}
else if ($idProjectOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
Expand Down Expand Up @@ -201,6 +207,11 @@
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
else if ($idProjectOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}

header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
exit;
Expand Down Expand Up @@ -259,7 +270,7 @@
print '<tr><td>'.$langs->trans("Color").'</td><td>';
print $formother->selectColor($color,'color');
print '</td></tr>';

// Parent category
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print $form->select_all_categories($type, $catorigin);
Expand Down
94 changes: 94 additions & 0 deletions htdocs/categories/categorie.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@
$dbtablename = 'socpeople&societe';
$fieldid = ! empty($ref)?'ref':'rowid';
}
elseif ($type == Categorie::TYPE_PROJECT) {
$elementtype = 'project';
$objecttype = 'project';
$objectid = isset($id)?$id:(isset($ref)?$ref:'');
$dbtablename = '&project';
$fieldid = ! empty($ref)?'ref':'rowid';
}
}

// Security check
Expand Down Expand Up @@ -145,6 +152,13 @@
$result = $object->fetch($objectid);
$elementtype = 'contact';
}
if ($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer)
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$object = new Project($db);
$result = $object->fetch($objectid);
$elementtype = 'project';
}
$cat = new Categorie($db);
$result=$cat->fetch($removecat);

Expand Down Expand Up @@ -192,6 +206,13 @@
$result = $object->fetch($objectid);
$elementtype = 'contact';
}
if ($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer)
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$object = new Project($db);
$result = $object->fetch($objectid);
$elementtype = 'project';
}
$cat = new Categorie($db);
$result=$cat->fetch($parent);

Expand Down Expand Up @@ -607,6 +628,75 @@

formCategory($db,$object,4,$socid, $user->rights->societe->creer);
}

if ($type == Categorie::TYPE_PROJECT)
{
$langs->load("products");

/*
* Category card for product
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

// Product
$product = new Product($db);
$result = $product->fetch($id, $ref);

llxHeader("","",$langs->trans("Project"));


$head=project_prepare_head($product);
$titre=$langs->trans("Project");
$picto=($object->public?'projectpub':'project');
dol_fiche_head($head, 'category', $titre,0,$picto);


print '<table class="border" width="100%">';

$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';

// Ref
print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
// Define a complementary filter for search of next/prev ref.
if (! $user->rights->projet->all->lire)
{
$objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
$object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
}
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
print '</td></tr>';

// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';

// Third party
print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
if ($object->thirdparty->id > 0) print $object->thirdparty->getNomUrl(1, 'project');
else print'&nbsp;';
print '</td></tr>';

// Visibility
print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
if ($object->public) print $langs->trans('SharedProject');
else print $langs->trans('PrivateProject');
print '</td></tr>';

// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';

// Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print dol_print_date($object->date_start,'day');
print '</td></tr>';

// Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
print dol_print_date($object->date_end,'day');
print '</td></tr>';

formCategory($db,$product,0,$socid,($user->rights->projet->creer));
}
}


Expand All @@ -630,6 +720,7 @@ function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1)
if ($typeid == Categorie::TYPE_CUSTOMER) $title = $langs->trans("CustomersProspectsCategoriesShort");
if ($typeid == Categorie::TYPE_MEMBER) $title = $langs->trans("MembersCategoriesShort");
if ($typeid == Categorie::TYPE_CONTACT) $title = $langs->trans("ContactCategoriesShort");
if ($typeid == Categorie::TYPE_PROJECT) $title = $langs->trans("ProjectsCategoriesShort");

$linktocreate='';
if ($showclassifyform && $user->rights->categorie->creer)
Expand Down Expand Up @@ -674,6 +765,7 @@ function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1)
if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyIsInCustomersCategories");
if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberIsInCategories");
if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactIsInCategories");
if ($typeid == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectIsInCategories");
print "\n";
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$title.':</td></tr>';
Expand All @@ -699,6 +791,7 @@ function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1)
if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer;
if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer;
if ($typeid == Categorie::TYPE_CONTACT) $permission=$user->rights->societe->creer;
if ($typeid == Categorie::TYPE_PROJECT) $permission=$user->rights->projet->creer;
if ($permission)
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removecat=".$cat->id."'>";
Expand Down Expand Up @@ -727,6 +820,7 @@ function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1)
if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyHasNoCategory");
if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberHasNoCategory");
if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactHasNoCategory");
if ($typeid == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectHasNoCategory");
print $title;
print "<br/>";
}
Expand Down
33 changes: 26 additions & 7 deletions htdocs/categories/class/categorie.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Categorie extends CommonObject
const TYPE_CONTACT = 4; // TODO Replace this value with 'contact'
const TYPE_USER = 4; // categorie contact and user are same ! TODO Replace this value with 'user'
const TYPE_ACCOUNT = 5; // for bank account TODO Replace this value with 'account'
const TYPE_PROJECT = 6;

/**
* @var array ID mapping from type string
Expand All @@ -64,6 +65,7 @@ class Categorie extends CommonObject
'contact' => 4,
'user' => 4,
'account' => 5,
'project' => 6,
);
/**
* @var array Foreign keys mapping from type string
Expand All @@ -78,6 +80,7 @@ class Categorie extends CommonObject
'contact' => 'socpeople',
'user' => 'user',
'account' => 'account',
'project' => 'project',
);
/**
* @var array Category tables mapping from type string
Expand All @@ -92,6 +95,7 @@ class Categorie extends CommonObject
'contact' => 'contact',
'user' => 'user',
'account' => 'account',
'project' => 'project',
);
/**
* @var array Object class mapping from type string
Expand All @@ -106,6 +110,7 @@ class Categorie extends CommonObject
'contact' => 'Contact',
'user' => 'User',
'account' => 'Account',
'project' => 'Project',
);
/**
* @var array Object table mapping from type string
Expand All @@ -120,6 +125,7 @@ class Categorie extends CommonObject
'contact' => 'socpeople',
'user' => 'user',
'account' => 'bank_account',
'project' => 'project',
);

public $element='category';
Expand All @@ -146,6 +152,7 @@ class Categorie extends CommonObject
* @see Categorie::TYPE_CONTACT
* @see Categorie::TYPE_USER
* @see Categorie::TYPE_ACCOUNT
* @see Categorie::TYPE_PROJECT
*/
var $type;

Expand Down Expand Up @@ -514,6 +521,18 @@ function delete($user)
$error++;
}
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_project";
$sql .= " WHERE fk_category = ".$this->id;
if (!$this->db->query($sql))
{
$this->error=$this->db->lasterror();
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
$error++;
}
}

if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang";
Expand Down Expand Up @@ -1029,11 +1048,11 @@ function debug_cats()


/**
* Returns all categories
* Returns all categories
*
* @param int $type Type of category
* @param boolean $parent Just parent categories if true
* @return array Table of Object Category
* @return array Table of Object Category
*/
function get_all_categories($type=null, $parent=false)
{
Expand Down Expand Up @@ -1183,7 +1202,7 @@ function print_all_ways($sep = " &gt;&gt; ", $url='', $nocolor=0)
}
}
}

if ($url == '')
{
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$cat->id.'&type='.$cat->type.'" class="'.$forced_color .'">';
Expand All @@ -1196,7 +1215,7 @@ function print_all_ways($sep = " &gt;&gt; ", $url='', $nocolor=0)
}
}
$newcategwithpath = preg_replace('/toreplace/', $forced_color, implode($sep, $w));

$ways[] = $newcategwithpath;
}

Expand Down Expand Up @@ -1239,8 +1258,8 @@ function get_meres()
}

/**
* Returns in a table all possible paths to get to the category
* starting with the major categories represented by Tables of categories
* Returns in a table all possible paths to get to the category
* starting with the major categories represented by Tables of categories
*
* @return array
*/
Expand Down Expand Up @@ -1415,7 +1434,7 @@ function getNomUrl($withpicto=0,$option='',$maxlength=0)
$b = hexdec($hex[4].$hex[5]);
$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
if ($bright >= 0.5) $forced_color='categtextblack'; // Higher than 60%
}
}

$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color .'">';
$linkend='</a>';
Expand Down
1 change: 1 addition & 0 deletions htdocs/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoriesArea");
elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactsCategoriesArea");
elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesArea");
elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesArea");
else $title=$langs->trans("CategoriesArea");

$arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
Expand Down
3 changes: 2 additions & 1 deletion htdocs/categories/photos.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
else $title=$langs->trans("Category");

$head = categories_prepare_head($object,$type);
Expand Down Expand Up @@ -140,7 +141,7 @@
print $langs->trans("Color").'</td><td>';
print $formother->showColor($object->color);
print '</td></tr>';

print "</table>\n";

print "</div>\n";
Expand Down
3 changes: 2 additions & 1 deletion htdocs/categories/traduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
else $title=$langs->trans("Category");

$head = categories_prepare_head($object,$type);
Expand Down Expand Up @@ -207,7 +208,7 @@
$doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 3, 80);
$doleditor->Create();
print '</td></tr>';

print '</tr>';
print '</table>';
}
Expand Down

0 comments on commit a4ce756

Please sign in to comment.