<?php
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version

	POSH is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
$xmlmanagersearch_getUserManagers = "SELECT DISTINCT id,long_name,username
                                     FROM users_hierarchy uh
                                     INNER JOIN users AS u ON uh.manager_id = u.id
                                     WHERE uh.user_id = %u";                                  
$scrmanager_deleteManager = "DELETE FROM users_hierarchy WHERE user_id = %u AND manager_id = %u";
$scrmanager_addManager = "INSERT INTO users_hierarchy (user_id,manager_id) VALUES (%u,%u)";
$organigram_getData = "SELECT * FROM users_hierarchy";
$organigram_getSelectedUserBranch= "SELECT b.user_id, a.manager_id,u.id,u.picture,u.long_name  
FROM users_hierarchy a 
LEFT JOIN users_hierarchy b ON a.manager_id = b.manager_id 
LEFT JOIN users u ON b.user_id = u.id  
WHERE a.user_id=%u 
OR a.manager_id=%u 
GROUP BY b.user_id 
ORDER BY a.manager_id";
$organigram_getUserData= "SELECT id,long_name,picture FROM users WHERE id=%u";
$organigram_getGroupUserData= 'SELECT id, long_name, picture, email FROM users WHERE id IN (%s)';
$organigram_getUserBranch= 'SELECT user_id managed, manager_id manager, branch  
FROM `users_hierarchy`
WHERE branch LIKE %s  
ORDER BY manager_id';
$xmlorganigramnetworksearch_getUserByNamePart = "
	SELECT 	u.id,
			u.long_name,
			u.username,
			u.email,
			u.picture,
			u.stat,
			u.statdate,
			u.description,
			u.activity,
            u.lastconnect_date,
			NOW() AS dbdate
	FROM 	users AS u
	WHERE 	long_name LIKE %s
		AND typ IN ('I','A') AND u.id!=%u 
	ORDER BY long_name
	LIMIT 	%u,11";

$scrmanager_addManager = "INSERT INTO users_hierarchy (user_id,branch_manager) VALUES (%u,%s)";
$organigram_getManagerBranch = "SELECT * FROM users_hierarchy WHERE branch LIKE %s AND manager_id=%u LIMIT 1";
$organigram_getAllManagerBranch = "SELECT * FROM users_hierarchy WHERE branch LIKE %s ";//OR user_id=%u";
$organigram_getAllManagedBranch = "SELECT * FROM users_hierarchy WHERE branch LIKE %s";
$organigram_updateAllManagerBranch = "UPDATE users_hierarchy SET branch = REPLACE(branch,',%u,',%s) WHERE branch LIKE %s";
$organigram_delAllManagerBranch = "UPDATE users_hierarchy SET branch = REPLACE(branch,%s,',%u,') WHERE branch LIKE %s";
$scrmanager_addNewManager = "INSERT INTO users_hierarchy (user_id,manager_id,branch) VALUES (%u,%u,%s)";
$xml_getMyPosition = "SELECT branch FROM `users_hierarchy` WHERE (branch LIKE %s OR branch LIKE %s) OR (branch LIKE %s OR branch LIKE %s) LIMIT 1";
$xml_getMaxBranch = "SELECT max(branch) AS branch FROM `users_hierarchy` WHERE  user_id=%u";
$xml_searchMyPosition = "SELECT branch FROM `users_hierarchy` WHERE branch LIKE %s LIMIT 1";
$xmlnetworksearch_getUserByKeywordsAndEmail = "
                SELECT DISTINCT 	u.id,
									u.long_name,
									u.username,
									u.email,
									u.picture,
									u.stat,
									u.statdate,
									u.description,
									u.activity,
									u.lastconnect_date,
									NOW() AS dbdate 
                FROM users u,
                     network_keywords nk,
                     search_keyword sk
                WHERE  (
					( sk.label_simplified IN (%s) 
                            %s
							
                        )
                        AND u.typ IN ('I','A') 
                        AND sk.id=nk.kw_id 
                        AND (
                            (u.id=nk.user_id AND nk.friend_id=0) 
                            OR 
                            (nk.user_id=%u AND nk.friend_id=u.id)
                            ) 
						) OR (%s) AND  u.id!=%u 
                ORDER BY u.long_name LIMIT %u,11 ";
$organigram_checkIfManager = "SELECT branch FROM users_hierarchy WHERE branch LIKE %s";
?>