Skip to content

Commit

Permalink
Merge pull request #1558 from joebordes/hacktoberfest2023
Browse files Browse the repository at this point in the history
feat(GenDoc) link and denormalization support, fix error with order by
  • Loading branch information
joebordes committed Sep 30, 2023
2 parents 2e415fb + d82a5fb commit c0b80fa
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 75 deletions.
8 changes: 4 additions & 4 deletions modules/evvtgendoc/DetailViewWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* http://vizsage.com/license/Vizsage-License-BY-NC-SA.html and the handy reference for understanding
* the full license at http://vizsage.com/license/Vizsage-Deed-BY-NC-SA.html. Unless required by
* applicable law or agreed to in writing, any software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the
* License terms of Creative Commons Attribution-NonCommercial-ShareAlike 3.0 (the License).
*************************************************************************************************
Expand All @@ -23,10 +23,10 @@
$forrecord = vtlib_purify($_REQUEST['forrecord']);
$crmEntityTable = CRMEntity::getcrmEntityTableAlias('Documents');
$templates=$adb->pquery(
'SELECT notesid,title
'SELECT vtiger_notes.notesid,vtiger_notes.title,vtiger_notes.note_no
FROM vtiger_notes
INNER JOIN '.$crmEntityTable.' ON vtiger_crmentity.crmid = vtiger_notes.notesid
WHERE deleted = 0 and template=1 and template_for=? order by title',
INNER JOIN '.$crmEntityTable.' ON vtiger_crmentity.crmid=vtiger_notes.notesid
WHERE deleted=0 and template=1 and template_for=? order by title',
array($moduletemplate)
);
$tpls = array();
Expand Down
2 changes: 1 addition & 1 deletion modules/evvtgendoc/GetTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require_once 'data/CRMEntity.php';
$crmEntityTable = CRMEntity::getcrmEntityTableAlias('Documents');
$templates=$adb->pquery(
'SELECT notesid,title
'SELECT vtiger_notes.notesid,vtiger_notes.title
FROM vtiger_notes
INNER JOIN '.$crmEntityTable.' ON vtiger_crmentity.crmid = vtiger_notes.notesid
WHERE vtiger_crmentity.deleted = 0 and template=1 and template_for=? order by title',
Expand Down
113 changes: 64 additions & 49 deletions modules/evvtgendoc/OpenDocument.php

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions modules/evvtgendoc/OpenDocument/DrawGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
/**
* OpenDocument_DrawGraph class
*
* This file is based on the work done by Alexander Pak <irokez@gmail.com>
* in his OpenDocument Library distributed on PEAR.
* A special thanks to him for setting the road we followed.
* This library is governed by the GNU Lesser Public License
* This file is based on the work done by Alexander Pak <irokez@gmail.com>
* in his OpenDocument Library distributed on PEAR.
* A special thanks to him for setting the road we followed.
* This library is governed by the GNU Lesser Public License
*
* The whole library 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category File Formats
* @package OpenDocument
* @author Joe Bordes, JPL TSolucio, S.L. <joe@tsolucio.com>
* Copyright 2009 JPL TSolucio, S.L. -- This file is a part of coreBOS.
* Copyright 2009 JPL TSolucio, S.L. -- This file is a part of coreBOS.
*/

require_once 'Element.php';
Expand All @@ -29,7 +29,7 @@
* @category File Formats
* @package OpenDocument
* @author Alexander Pak <irokez@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @version 0.1.0
* @link http://pear.php.net/package/OpenDocument
* @since File available since Release 0.1.0
Expand Down Expand Up @@ -69,6 +69,7 @@ public function __construct(DOMNode $node, OpenDocument $document) {
'OpenDocument_DrawCustomShape',
'OpenDocument_DrawGraph',
'OpenDocument_DrawConnector',
'OpenDocument_DrawLink',
'OpenDocument_DrawLine',
'OpenDocument_DrawRect',
'OpenDocument_Frame',
Expand Down Expand Up @@ -112,6 +113,9 @@ public function generateStyleName() {
public function createDrawGraph() {
return OpenDocument_DrawGraph::instance($this);
}
public function createDrawLink() {
return OpenDocument_DrawLink::instance($this);
}
public function createDrawLine() {
return OpenDocument_DrawLine::instance($this);
}
Expand Down
138 changes: 138 additions & 0 deletions modules/evvtgendoc/OpenDocument/DrawLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* OpenDocument_DrawLink class
*
* This file is based on the work done by Alexander Pak <irokez@gmail.com>
* in his OpenDocument Library distributed on PEAR.
* A special thanks to him for setting the road we followed.
* This library is governed by the GNU Lesser Public License
*
* The whole library 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category File Formats
* @package OpenDocument
* @author Joe Bordes, JPL TSolucio, S.L. <joe@tsolucio.com>
* Copyright 2023 JPL TSolucio, S.L. -- This file is a part of coreBOS.
*/

require_once 'Element.php';

/**
* OpenDocument_DrawLink element
*
* @category File Formats
* @package OpenDocument
* @author Alexander Pak <irokez@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @version 0.1.0
* @link http://pear.php.net/package/OpenDocument
* @since File available since Release 0.1.0
*/
class OpenDocument_DrawLink extends OpenDocument_StyledElement {

/**
* Node namespace
*/
const nodeNS = OpenDocument::NS_DRAW;

/**
* Node amespace
*/
const nodePrefix = 'draw';

/**
* Node name
*/
const nodeName = 'a';

/**
* Element style name prefix
*/
const styleNamePrefix = 'dlk';

/**
* Constructor
*
* @param DOMNode $node
* @param OpenDocument $document
*/
public function __construct(DOMNode $node, OpenDocument $document) {
parent::__construct($node, $document);
$this->allowedElements = array(
'OpenDocument_Paragraph',
'OpenDocument_DrawCustomShape',
'OpenDocument_DrawGraph',
'OpenDocument_DrawConnector',
'OpenDocument_DrawLink',
'OpenDocument_DrawLine',
'OpenDocument_DrawRect',
'OpenDocument_Frame',
);
}

/**
* Create element instance
*
* @param mixed $object
* @param mixed $content
* @return OpenDocument_DrawLink
* @throws OpenDocument_Exception
*/
public static function instance($object) {
if ($object instanceof OpenDocument) {
$document = $object;
$node = $object->cursor;
} elseif ($object instanceof OpenDocument_Element) {
$document = $object->getDocument();
$node = $object->getNode();
} else {
throw new OpenDocument_Exception(OpenDocument_Exception::ELEM_OR_DOC_EXPECTED);
}

$element = new OpenDocument_DrawLink($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document);
$node->appendChild($element->node);

return $element;
}

/**
* Generate new style name
*
* @return string $stylename
*/
public function generateStyleName() {
self::$styleNameMaxNumber ++;
return self::styleNamePrefix . self::$styleNameMaxNumber;
}
public function createDrawGraph() {
return OpenDocument_DrawGraph::instance($this);
}
public function createDrawLink() {
return OpenDocument_DrawLink::instance($this);
}
public function createDrawLine() {
return OpenDocument_DrawLine::instance($this);
}
public function createDrawConnector() {
return OpenDocument_DrawConnector::instance($this);
}
public function createDrawRect() {
return OpenDocument_DrawRect::instance($this);
}
public function createDrawCustomShape() {
return OpenDocument_DrawCustomShape::instance($this);
}
public function createParagraph($text = '') {
return OpenDocument_Paragraph::instance($this, $text);
}
public function createFrame($text, $anchortype, $width, $height, $zindex, $framename, $x, $y, $anchorpagenumber) {
return OpenDocument_Frame::instance($this, $text, $anchortype, $width, $height, $zindex, $framename, $x, $y, $anchorpagenumber);
}
}
?>
14 changes: 9 additions & 5 deletions modules/evvtgendoc/OpenDocument/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
*
* This library 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category File Formats
* @package OpenDocument
* @author Alexander Pak <irokez@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @version 0.1.0
* @link http://pear.php.net/package/OpenDocument
* @since File available since Release 0.1.0
*
* Copyright 2009 JPL TSolucio, S.L. -- This file is a part of coreBOS.
* Copyright 2009 JPL TSolucio, S.L. -- This file is a part of coreBOS.
* Author: Joe Bordes
*/

Expand All @@ -36,7 +36,7 @@
* @category File Formats
* @package OpenDocument
* @author Alexander Pak <irokez@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @version 0.1.0
* @link http://pear.php.net/package/OpenDocument
* @since File available since Release 0.1.0
Expand Down Expand Up @@ -93,6 +93,7 @@ public function __construct(DOMNode $node, OpenDocument $document) {
'OpenDocument_Footnote',
'OpenDocument_ReferenceMark',
'OpenDocument_ReferenceRef',
'OpenDocument_DrawLink',
'OpenDocument_DrawLine',
'OpenDocument_DrawCustomShape',
);
Expand Down Expand Up @@ -226,6 +227,9 @@ public function createReferenceRef($text) {
public function createDrawGraph() {
return OpenDocument_DrawGraph::instance($this);
}
public function createDrawLink() {
return OpenDocument_DrawLink::instance($this);
}
public function createDrawLine() {
return OpenDocument_DrawLine::instance($this);
}
Expand Down
12 changes: 10 additions & 2 deletions modules/evvtgendoc/compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,13 @@ function retrieve_from_db($marcador, $id, $module, $applyformat = true) {
} elseif (areModulesRelated($token_pair[0], $module)) {
$reemplazo = retrieve_from_db($marcador, $focus->column_fields[$related_module[$module][$token_pair[0]]], $token_pair[0], $applyformat);
} elseif ($token_pair[0] == 'Organization' || $token_pair[0] == 'cbCompany') {
$res = $adb->query('SELECT * FROM vtiger_cbcompany INNER JOIN vtiger_crmentity on crmid=cbcompanyid WHERE deleted=0 AND defaultcompany=1');
$crmEntityTable = CRMEntity::getcrmEntityTableAlias('cbCompany');
$res = $adb->query(
'SELECT *
FROM vtiger_cbcompany
INNER JOIN '.$crmEntityTable.' on vtiger_crmentity.crmid=cbcompanyid
WHERE defaultcompany=1 and vtiger_crmentity.deleted=0'
);
$org_fields = $adb->getFieldsArray($res);
if (in_array($token_pair[1], $org_fields)) {
$reemplazo = $adb->query_result($res, 0, $token_pair[1]);
Expand Down Expand Up @@ -950,6 +956,7 @@ function eval_paracada($condition, $id, $module, $check = false) {
} else {
$sortinfo = false;
}
OpenDocument::debugmsg(array('SORT ORDER OF FOREACH' => $sortinfo));
$related = getRelatedCRMIDs($relatedsql['query'], $sortinfo);
} else {
if (areModulesRelated($token_pair[0], $module)) {
Expand Down Expand Up @@ -1842,7 +1849,8 @@ function getUitypefield($module, $fieldname) {

function getRelatedCRMIDs($relsql, $sortinfo = false) {
global $adb;
$relsql = empty($sortinfo) ? $relsql : $relsql . ' ORDER BY ' . $sortinfo['cname'] . ' ' . $sortinfo['order'];
$relsql = empty($sortinfo) || stripos($relsql, ' ORDER BY ')!==false ? $relsql : $relsql . ' ORDER BY ' . $sortinfo['cname'] . ' ' . $sortinfo['order'];
OpenDocument::debugmsg(array('FOREACH QUERY' => $relsql));
$res = $adb->pquery($relsql, array());
$nr = $adb->num_rows($res);
$ret = array('entries' => array());
Expand Down
10 changes: 5 additions & 5 deletions modules/evvtgendoc/gendocAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* http://vizsage.com/license/Vizsage-License-BY-NC-SA.html and the handy reference for understanding
* the full license at http://vizsage.com/license/Vizsage-Deed-BY-NC-SA.html. Unless required by
* applicable law or agreed to in writing, any software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the
* License terms of Creative Commons Attribution-NonCommercial-ShareAlike 3.0 (the License).
*************************************************************************************************
Expand Down Expand Up @@ -43,11 +43,11 @@
);
$context = [
'GDTemplateID' => $fileid,
'GDTemplateName' => $adb->query_result($orgfile, 0, 'title'),
'GDTemplateName' => decode_html($adb->query_result($orgfile, 0, 'title')),
'GDTemplateNumber' => $adb->query_result($orgfile, 0, 'note_no'),
];
$mergeTemplatePath=$adb->query_result($orgfile, 0, 'filepath');
$mergeTemplateName=$adb->query_result($orgfile, 0, 'name');
$mergeTemplatePath = decode_html($adb->query_result($orgfile, 0, 'filepath'));
$mergeTemplateName = decode_html($adb->query_result($orgfile, 0, 'name'));
$mergetemplate = $adb->query_result($orgfile, 0, 'mergetemplate');
if ($mergetemplate=='1') {
$mergetemplatefor = $adb->query_result($orgfile, 0, 'template_for');
Expand Down Expand Up @@ -134,7 +134,7 @@
rename(($format=='doc'?$filename:$pdfname), $sname);
break;
case 'save':
$docid = OpenDocument::saveAsDocument($record, $module, $format, basename($mergeTemplateName, '.odt'), ($format=='pdf' ? $fullpdfname : $fullfilename), $name);
$docid = OpenDocument::saveAsDocument($record, $module, $format, basename($mergeTemplateName, '.odt'), ($format=='pdf' ? $fullpdfname : $fullfilename), $name, true, $holdUser->id);
echo '<script>window.parent.postMessage('.$docid.', "*");</script>';
break;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/evvtgendoc/odt.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
WHERE n.notesid=?",
array($fileid)
);
$mergeTemplatePath=$adb->query_result($orgfile, 0, 'filepath');
$mergeTemplateName=$adb->query_result($orgfile, 0, 'name');
$mergeTemplatePath = decode_html($adb->query_result($orgfile, 0, 'filepath'));
$mergeTemplateName = decode_html($adb->query_result($orgfile, 0, 'name'));
$mergetemplate = $adb->query_result($orgfile, 0, 'mergetemplate');
if ($mergetemplate=='1') {
$mergetemplatefor = $adb->query_result($orgfile, 0, 'template_for');
Expand Down

0 comments on commit c0b80fa

Please sign in to comment.