   PRIMARY KEY  (`id`)
 );
 
-
-/* 	SELECTING GROUPS FOR EACH USER
-	
-*/
-
-SELECT `ipp_group`.`name`
-FROM `ipp_group`
-INNER JOIN `ipp_group_join`
-ON `ipp_group_join`.`group_id` = `ipp_group`.`id`
-INNER JOIN `ipp_users`
-ON `ipp_group_join`.`user_id` = `ipp_users`.`id`
-WHERE `ipp_group_join`.`user_id` = /* Current user id */
-
-
-
 /* 	CREATING IPP_DOCUMENTS TABLE
 */
 

  `superadmin` BOOLEAN default FALSE,
  PRIMARY KEY  (`id`)
);

/* 	REGISTERING SUPERADMIN
	Password has to be hashed, SALT to be determined by hashing creation_date, no avatar img yet
*/

INSERT INTO `ipp_users` (`first_name`, `last_name`, `password`, `creation_date`, `email`, `avatar`, `superadmin`)
VALUES					('super', 'admin', 'adminpwd', 'admin_creation_date', 'admin.internet@programming.fi', 'to_be_defined', TRUE);

/* 	REGISTERING STANDARD USERS
	Password has to be hashed !!!
	First run loggin SQL to check that given email/password are unique in the table !
*/

INSERT INTO `ipp_users` (`first_name`, `last_name`, `password`, `creation_date`, `email`, `avatar`)
VALUES					(/* user_input */, /* user_input */, /* user_input */, /* generated_creation_date */, /* user_input */, /* manage file upload */);

/* 	LOGGING USERS IN
	total should be = 1 that means, only one match, then loggin is succesful
	if total = 0, ask for registration
	if total > 1, we have a structural problem, because two users in the table have been registered with identical emails and passwords...
*/

SELECT count(`id`) as total 
FROM `ipp_users` 
WHERE `email`=/* user_input */
AND `password`=/* user_input */

/* 	CREATING IPP_GROUP TABLE
*/

INNER JOIN `ipp_group`
ON `ipp_group`.`id` = `ipp_document`.`group_id`
WHERE `ipp_document`.`group_id` = /* Current group id */



/*	CREATION OF NEW GROUP BY USER 
*/

INSERT INTO `ipp_group` (`name`, `admin`, `color_code`)
VALUES					(/* user_input */, /* current_user_id */, /* generated with PHP */);

INSERT INTO `ipp_group_join` 	(`user_id`, `group_id`, `moderator`)
VALUES							(/* current_user_id */, /* current_group_id */, TRUE);



/*	ADDING NEW USER TO A GROUP 
*/


INSERT INTO `ipp_group_join` 	(`user_id`, `group_id`, `moderator`)
VALUES							(/* current_user_id */, /* current_group_id */, FALSE);


/*	CREATING A DOCUMENT (ALWAYS WITHIN A GROUP) 
*/


INSERT INTO `ipp_group_join` 	(`name`, `admin_id`, `group_id`, `creation_date`)
VALUES							(/* user_input */, /* current_user_id */, /* current_group_id */, /* current_timestamp */);


/*	DELETING A DOCUMENT 
*//* SHOULD ONLY BE ALLOWED IF */

SELECT `ipp_document`.`admin_id`
FROM `ipp_document` 
WHERE `document_id`=/* current_document_id */

/* == USER_ID -> MEANING THAT ONLY DOCUMENT'S ADMIN CAN DELETE THEM (DUH...) */

DELETE FROM `ipp_document` WHERE `ipp_document`.`id` = /* document_id */ ;



/*	DELETING A GROUP
*//* SHOULD ONLY BE ALLOWED IF */

SELECT count(`id`) as total 
FROM `ipp_group_join` 
WHERE `group_id`=/* group_id */

/* ==1 -> MEANING THERE IS ONLY ONE USER LEFT IN THE GROUP */

DELETE FROM `ipp_document` WHERE `ipp_document`.`group_id` = /* document's_group_id */ ;
DELETE FROM `ipp_group` WHERE `ipp_group`.`id` = /* group_id */ ;


/*	OTHERWISE: LEAVING A GROUP
*//* IMPLIES PICKING A NEW MODERATOR IF CURRENT USER WAS MODERATOR */


DELETE FROM `ipp_group_join` WHERE `ipp_group_join`.`group_id` = /* group_id */ AND `ipp_group_join`.`user_id` = /* user_id */;



/*	DELETING A USER 
*/


/* SHALL WE SIMPLY FLAG THEM FOR POSSIBLE FURTHER RECOVERY ? */



/*	 WHAT ELSE ?
*/

