Manual adding projects via exterior application

Discuss about Group-Office development here

Moderator: Developers

raven
Posts: 5
Joined: Fri Nov 06, 2009 10:48 am

Manual adding projects via exterior application

Postby raven » Fri Nov 06, 2009 2:31 pm

Hi.
I need to add new projects via exterior application.
The only way to do it is to change GO tables from the side of this application.
I insert new records in the 'pm_projects' and 'ab_contacts' tables, and all things go rightly:
new project (with new contact) and new contact appear, and for this new project the right hand panel 'Project information' looks like this:
===================================
Information about orders
Folder for storing orders
ID: 8
Manager: Collaboration Administrator
Status: Ongoing
Customer: test
Created at: 10-31-2009
Contact: tttt
Start time: 10-31-2009
Units booked: 0/12.45
===================================
But I could not add links and units number (first number in the last line: 'Units booked...', currently is zero):

1. I insert one row into 'go_links_5' and 'go_links_2' tables, accordingly to $GO_LINKS->add_links() function. If, for example, project_id = 12 and contact_id=23, this insertings look like these:
INSERT INTO `go_links_5` (`id`, `link_id`, `link_type`, `description`, `ctime`) VALUES (12, 23, 2, '', UNIX_TIMESTAMP())
INSERT INTO `go_links_2` (`id`, `link_id`, `link_type`, `description`, `ctime`) VALUES (23, 12, 5, '', UNIX_TIMESTAMP())
The records are really inserted, but links don't appear at the GO panels!

2. In order to add units number I insert one row into the `pm_hours` table, like this:
INSERT INTO `pm_hours` (`id`, `user_id`, `date`, `units`) VALUES (1, 1, UNIX_TIMESTAMP(), 2)
The row is really inserted, but the info does not change!
(Remains 'Units booked: 0/12.45', instead of 'Units booked: 2/12.45')

Can anyone explain me, what's wrong?

Thanks.
mschering
Site Admin
Site Admin
Posts: 8284
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Manual adding projects via exterior application

Postby mschering » Mon Nov 09, 2009 3:26 pm

You should use the PHP API.

require the projects class:

Code: Select all

require_once ($GO_MODULES->modules['projects']['class_path']."projects.class.inc.php");
$projects = new projects();
here's a snippet of adding a project:

Code: Select all

case 'save_project':

			require_once ($GO_LANGUAGE->get_language_file('projects'));
			
			$project_id=$project['id']=isset($_POST['project_id']) ? ($_POST['project_id']) : 0;
			$project['name']=$_POST['name'];
			$project['description']=$_POST['description'];

			$project['responsible_user_id']=$_POST['responsible_user_id'];
				
			if(isset($_POST['customer']))
			$project['customer']=$_POST['customer'];
			
			if(isset($_POST['contact']))
				$project['contact']=$_POST['contact'];
	
			if(isset($_POST['contact_id']))
				$project['contact_id']=$_POST['contact_id'];
			
			$project['status_id']=$_POST['status_id'];
			$project['archived']=isset($_POST['archived']) ? '1' : '0';
			if(isset($_POST['company_id']))
			$project['company_id']=$_POST['company_id'];		
				
			$project['due_time']=Date::to_unixtime($_POST['due_time']);
			$project['start_time']=Date::to_unixtime($_POST['start_time']);
			$project['units_budget']=Number::to_phpnumber($_POST['units_budget']);
				
			$project['parent_project_id']=$_POST['parent_project_id'];
				
			//$project['select_fee']=isset($_POST['select_fee']) ? '1' : '0';
				
			$project['int_fee']=Number::to_phpnumber($_POST['int_fee']);
			$project['ext_fee']=Number::to_phpnumber($_POST['ext_fee']);

			if(empty($project['name']))
			{
				throw new Exception($lang['common']['missingField']);
			}

			$existing_project = $projects->get_project_by_name($project['name'], $project['parent_project_id']);

			if($project['id']>0)
			{
				if($existing_project && $existing_project['id']!=$project['id'])
				{
					throw new Exception($lang['projects']['projectExists']);
				}
				if(isset($_POST['type_id']))
				{
					$project['type_id']=$_POST['type_id'];
				}

				$old_project = $existing_project ? $existing_project : $projects->get_project($project['id']);
				$type = $projects->get_type($old_project['type_id']);

				if(!$GO_SECURITY->has_permission($GO_SECURITY->user_id, $type['acl_write']))
				{
					throw new AccessDeniedException();
				}

				$projects->update_project($project,$type, $old_project);
				$response['parent_project_id'] = $project['parent_project_id'];
				$response['success']=true;
				$insert=false;
			}else
			{
				if($existing_project)
				{
					throw new Exception($lang['projects']['projectExists']);
				}
				if(isset($_POST['type_id']))
				{
					$project['type_id']=$_POST['type_id'];
				}else
				{
					$parentproject = $projects->get_project($project['parent_project_id']);
					$project['type_id']=$parentproject['type_id'];
				}

				//debug($project['type_id']);
				$type = $projects->get_type($project['type_id']);

				if(!$GO_SECURITY->has_permission($GO_SECURITY->user_id, $type['acl_write']))
				{
					throw new AccessDeniedException();
				}

				$project['user_id']=$GO_SECURITY->user_id;


				$project_id= $projects->add_project($project,$type);

				$response['parent_project_id'] = $project['parent_project_id'];
				$response['project_id']=$project_id;
				$response['success']=true;
				$insert=true;
			}
				
			if(isset($GO_MODULES->modules['customfields']) && $GO_MODULES->modules['customfields']['read_permission'])
			{
				require_once($GO_MODULES->modules['customfields']['class_path'].'customfields.class.inc.php');
				$cf = new customfields();
				$cf->update_fields($GO_SECURITY->user_id, $project_id, 5, $_POST, $insert);
			}

			if(!empty($_POST['link']))
			{
				$link_props = explode(':', $_POST['link']);
				$GO_LINKS->add_link(
				($link_props[1]),
				($link_props[0]),
				$project_id,
				5);
			}
				
			if(isset($project['company_id']))
			{
				$GO_LINKS->add_link($project['company_id'], 3, $project_id, 5);
			}

			if(isset($project['contact_id']))
			{
				$GO_LINKS->add_link($project['contact_id'], 2, $project_id, 5);
			}
			
			if(!empty($_POST['template_id']))
			{
				require_once($GO_MODULES->modules['files']['class_path'].'files.class.inc.php');
				$files = new files();

				$template = $projects->get_template($_POST['template_id']);
				$fs = new filesystem();

				$destination_folder = $files->get_folder($project['files_folder_id']);
				

				$template_path = $GO_CONFIG->file_storage_path.'templates/'.$template['id'];
				$project_path = $GO_CONFIG->file_storage_path.$files->build_path($destination_folder);


				$folders = $fs->get_folders($template_path);
				while($folder = array_shift($folders))
				{
					$fs->copy($folder['path'], $project_path.'/'.$folder['name']);
				}
				
				$fsfiles = $fs->get_files($template_path);
				while($file = array_shift($fsfiles))
				{
					$fs->copy($file['path'], $project_path.'/'.$file['name']);
				}

				$files->import_folder($project_path, $destination_folder['parent_id']);


				$projects->get_template_events($template['id']);

				$project_start_time = !empty($project['start_time']) ? $project['start_time'] : time();;
				$parent_project_id = $project['id'];
				$projects2 = new projects();
				while($record = $projects->next_record())
				{
					switch($record['type']){
						case 'project':
							
							unset($project['files_folder_id'], $project['id']);

							$project['responsible_user_id']=$record['user_id'];
							$project['parent_project_id']=$parent_project_id;
							$project['name']=$record['name'];
							$project['description']=$record['description'];
							$project['start_time']=Date::date_add($project_start_time, $record['time_offset']);

							$duration_days = ceil($record['duration']/24);
							$project['due_time']=Date::date_add($project['start_time'], $duration_days);

							$projects2->add_project($project, $type);

							break;
						case 'task':

							require_once($GO_MODULES->modules['tasks']['class_path'].'tasks.class.inc.php');
							$tasks = new tasks();

							$settings = $tasks->get_settings($record['user_id']);
							if(empty($settings['default_tasklist_id']))
							{
								$tasklist = $tasks->get_default_tasklist($record['user_id']);
								if(!$tasklist)
								{
									continue;
								}
								$settings['default_tasklist_id']=$tasklist['id'];
							}

							$task['name']=$record['name'];
							$task['start_time']=Date::date_add($project_start_time, $record['time_offset']);

							$duration_days = ceil($record['duration']/24);

							$task['due_time']=Date::date_add($task['start_time'], $duration_days);
							$task['description']=$record['description'];
							$task['status']='NEEDS-ACTION';
							$task['tasklist_id']=$settings['default_tasklist_id'];
							if(!empty($settings['remind']))
							{
								$task['reminder']=Date::to_unixtime(date($_SESSION['GO_SESSION']['date_format'], $task['start_time']).' '.$settings['remind_time']);
							}
							$task['user_id']=$record['user_id'];

							$task_id = $tasks->add_task($task);

							$GO_LINKS->add_link(
								$parent_project_id,
								5,
								$task_id,
								12);
							break;
					}
				}
				
			}

			break;
Best regards,

Merijn Schering
Intermesh
raven
Posts: 5
Joined: Fri Nov 06, 2009 10:48 am

Re: Manual adding projects via exterior application

Postby raven » Tue Nov 10, 2009 10:14 am

Thank you, but your advise doesn't fit my situation, described above:
all should be done from an EXTERIOR application,
therefore, I have neither GO core loaded, nor database configuration,
so GO class 'projects' will not work.
Moreover, I cannot see what it's methods $projects->add_project() and $projects->update_project() do: you told me use PHP API, but I cannot find them for the models, only for the base classes.
I really learnt how to add new project from this my exterior app using mysql_... - php functions only.
But I failed in the following two points:

1. Inserting records for links into 'go_links_5' and 'go_links_2' tables, exactly in accordance with $GO_LINKS->add_links() function, doesn't give rise for their appearance at the GO panels.

2. Inserting record into the 'pm_hours' table doesn't turn on [Number] in the 'Units booked: [Number]/[Sum]':
it remains zero.

So, my question still remains:
Can anyone explain, how to add correctly links and number of units budgeted using only mysql - php standard functions and what change in the tables should be done for this, but inserting rows into 'go_links_5', 'go_links_2' and 'pm_hours' tables, mentioned above?

Thanks.
mschering
Site Admin
Site Admin
Posts: 8284
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Manual adding projects via exterior application

Postby mschering » Wed Nov 11, 2009 9:55 am

Maybe you can include Group-Office.php so you can use those functions in your external app?
Best regards,

Merijn Schering
Intermesh
raven
Posts: 5
Joined: Fri Nov 06, 2009 10:48 am

Re: Manual adding projects via exterior application

Postby raven » Wed Nov 11, 2009 12:10 pm

Thank you, it's a good idea, but I have to include some other files in this case, haven't I?
I'll try it, but the best way I would like to manage tables.

By the way, the contacts which I add for links with the projects, doesn't appear in the list of links when editing project.
May be, you can advise, what to do in order to reveal them in this list of links? I add them with user_id=1, this is id of admin in the go_users table.
mschering
Site Admin
Site Admin
Posts: 8284
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Manual adding projects via exterior application

Postby mschering » Wed Nov 11, 2009 12:18 pm

Did you add those contacts with GO or with a custom external script?
Best regards,

Merijn Schering
Intermesh
raven
Posts: 5
Joined: Fri Nov 06, 2009 10:48 am

Re: Manual adding projects via exterior application

Postby raven » Wed Nov 11, 2009 12:58 pm

Custom way, of course.
mschering
Site Admin
Site Admin
Posts: 8284
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Manual adding projects via exterior application

Postby mschering » Wed Nov 11, 2009 2:06 pm

Then you probably did not ad them to the go_search_cache table. Run a database check to see if they appear.
Best regards,

Merijn Schering
Intermesh
raven
Posts: 5
Joined: Fri Nov 06, 2009 10:48 am

Re: Manual adding projects via exterior application

Postby raven » Wed Nov 11, 2009 4:14 pm

I didn't of course - I did never surmise it!
Thank you very much - it works! :D

Who is online

Users browsing this forum: No registered users and 2 guests

cron